Search in sources :

Example 1 with PortableReader

use of com.hazelcast.nio.serialization.PortableReader in project hazelcast by hazelcast.

the class ClientPartitionLostListenerTest method test_portableMapPartitionLostEvent_deserialization.

@Test
public void test_portableMapPartitionLostEvent_deserialization() throws IOException {
    final Address source = new Address();
    final PortablePartitionLostEvent event = new PortablePartitionLostEvent();
    final PortableReader reader = mock(PortableReader.class);
    final ObjectDataInput input = mock(ObjectDataInput.class);
    when(reader.getRawDataInput()).thenReturn(input);
    when(reader.readInt("p")).thenReturn(1);
    when(reader.readInt("l")).thenReturn(2);
    when(input.readObject()).thenReturn(source);
    event.readPortable(reader);
    assertEquals(1, event.getPartitionId());
    assertEquals(2, event.getLostBackupCount());
    assertEquals(source, event.getSource());
}
Also used : PortablePartitionLostEvent(com.hazelcast.spi.impl.PortablePartitionLostEvent) Address(com.hazelcast.nio.Address) HazelcastTestSupport.getAddress(com.hazelcast.test.HazelcastTestSupport.getAddress) ObjectDataInput(com.hazelcast.nio.ObjectDataInput) PortableReader(com.hazelcast.nio.serialization.PortableReader) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 2 with PortableReader

use of com.hazelcast.nio.serialization.PortableReader in project hazelcast by hazelcast.

the class DefaultPortableReaderQuickTest method reusingTheReader_multipleCalls_stateResetCorreclty.

@Test
public void reusingTheReader_multipleCalls_stateResetCorreclty() throws IOException {
    PortableReader reader = reader(PORSCHE);
    assertEquals("rear", reader.readUTF("wheels[1].name"));
    assertEquals(300, reader.readInt("engine.power"));
    assertEquals(46, reader.readInt("wheels[0].serial[0]"));
    try {
        reader.readFloat("wheels[0].serial[0]");
        fail();
    } catch (Exception ignored) {
    }
    assertEquals("front", reader.readUTF("wheels[0].name"));
    assertEquals(45, reader.readInt("wheels[1].serial[0]"));
    try {
        reader.readIntArray("name");
        fail();
    } catch (Exception ignored) {
    }
    assertEquals(15, reader.readInt("engine.chip.power"));
    assertEquals("Porsche", reader.readUTF("name"));
}
Also used : PortableReader(com.hazelcast.nio.serialization.PortableReader) HazelcastSerializationException(com.hazelcast.nio.serialization.HazelcastSerializationException) IOException(java.io.IOException) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Aggregations

PortableReader (com.hazelcast.nio.serialization.PortableReader)2 QuickTest (com.hazelcast.test.annotation.QuickTest)2 Test (org.junit.Test)2 Address (com.hazelcast.nio.Address)1 ObjectDataInput (com.hazelcast.nio.ObjectDataInput)1 HazelcastSerializationException (com.hazelcast.nio.serialization.HazelcastSerializationException)1 PortablePartitionLostEvent (com.hazelcast.spi.impl.PortablePartitionLostEvent)1 HazelcastTestSupport.getAddress (com.hazelcast.test.HazelcastTestSupport.getAddress)1 ParallelTest (com.hazelcast.test.annotation.ParallelTest)1 IOException (java.io.IOException)1