try { msg.writeUTF(null); } catch (NullPointerException e) { /* OK */ }
}
public void testRollback() throws Exception
{
BytesMessageImpl msg;
byte[] dummy = { (byte)1 , (byte)2 , (byte)3 };
// Boolean
msg = new BytesMessageImpl();
msg.writeBytes(dummy);
msg.reset();
assertEquals(true,msg.readBoolean());
// Byte
msg = new BytesMessageImpl();
msg.writeBytes(dummy);
msg.reset();
assertEquals(1,msg.readByte());
// Short
msg = new BytesMessageImpl();
msg.writeBytes(dummy);
msg.reset();
assertEquals(2+1*256,msg.readShort());
// Char
msg = new BytesMessageImpl();
msg.writeBytes(dummy);
msg.reset();
assertEquals(3,msg.readBytes(new byte[3]));
// Int
msg = new BytesMessageImpl();
msg.writeBytes(dummy);
msg.reset();
try { msg.readInt(); fail("Should have failed"); } catch (MessageEOFException e) { /* OK */ }
assertEquals(3,msg.readBytes(new byte[3]));
// Long
msg = new BytesMessageImpl();
msg.writeBytes(dummy);
msg.reset();
try { msg.readLong(); fail("Should have failed"); } catch (MessageEOFException e) { /* OK */ }
assertEquals(3,msg.readBytes(new byte[3]));
// Float
msg = new BytesMessageImpl();
msg.writeBytes(dummy);
msg.reset();
try { msg.readFloat(); fail("Should have failed"); } catch (MessageEOFException e) { /* OK */ }
assertEquals(3,msg.readBytes(new byte[3]));
// Double
msg = new BytesMessageImpl();
msg.writeBytes(dummy);
msg.reset();
try { msg.readDouble(); fail("Should have failed"); } catch (MessageEOFException e) { /* OK */ }
assertEquals(3,msg.readBytes(new byte[3]));
// String
msg = new BytesMessageImpl();
msg.writeBytes(dummy);
msg.reset();
try { msg.readUTF(); fail("Should have failed"); } catch (MessageEOFException e) { /* OK */ }
assertEquals(3,msg.readBytes(new byte[3]));
// Bytes
msg = new BytesMessageImpl();
msg.writeBytes(dummy);
msg.reset();
byte[] data = new byte[3];
assertEquals(3,msg.readBytes(data));
System.out.println(data[0]);
assertEquals(1, data[0]);
assertEquals(2, data[1]);
assertEquals(3, data[2]);
assertEquals(10, msg.getBodyLength());
}