Search in sources :

Example 16 with InMessage

use of edu.iu.dsc.tws.comms.dfw.InMessage in project twister2 by DSC-SPIDAL.

the class KeyedSerializerTest method testBuildLargeListByteMessage.

@SuppressWarnings("Unchecked")
@Test
public void testBuildLargeListByteMessage() {
    int numBuffers = 32;
    int size = 1000;
    List<Object> data = new AggregatedObjects<>();
    for (int i = 0; i < 4; i++) {
        Object o = createKeyedData(800, MessageTypes.BYTE_ARRAY, MessageTypes.BYTE_ARRAY);
        data.add(o);
    }
    InMessage inMessage = keyedListValueCase(numBuffers, size, data, MessageTypes.BYTE_ARRAY, MessageTypes.BYTE_ARRAY);
    List<Object> result = (List<Object>) inMessage.getDeserializedData();
    for (int i = 0; i < result.size(); i++) {
        Tuple deserializedData = (Tuple) result.get(i);
        Tuple d = (Tuple) data.get(i);
        Assert.assertArrayEquals((byte[]) deserializedData.getKey(), (byte[]) ((Tuple) d).getKey());
        Assert.assertArrayEquals((byte[]) deserializedData.getValue(), (byte[]) ((Tuple) d).getValue());
    }
}
Also used : InMessage(edu.iu.dsc.tws.comms.dfw.InMessage) List(java.util.List) Tuple(edu.iu.dsc.tws.api.comms.structs.Tuple) Test(org.junit.Test)

Example 17 with InMessage

use of edu.iu.dsc.tws.comms.dfw.InMessage in project twister2 by DSC-SPIDAL.

the class KeyedSerializerTest method testBuildLargeLongMessage.

@Test
public void testBuildLargeLongMessage() {
    int numBuffers = 10;
    int size = 1000;
    MessageType type = MessageTypes.LONG_ARRAY;
    Object data = createKeyedData(800, type, MessageTypes.LONG);
    InMessage inMessage = keyedSingleValueCase(numBuffers, size, type, MessageTypes.LONG, data);
    Tuple deserializedData = (Tuple) inMessage.getDeserializedData();
    Assert.assertEquals((long) deserializedData.getKey(), (long) ((Tuple) data).getKey());
    Assert.assertArrayEquals((long[]) deserializedData.getValue(), (long[]) ((Tuple) data).getValue());
}
Also used : InMessage(edu.iu.dsc.tws.comms.dfw.InMessage) MessageType(edu.iu.dsc.tws.api.comms.messaging.types.MessageType) Tuple(edu.iu.dsc.tws.api.comms.structs.Tuple) Test(org.junit.Test)

Example 18 with InMessage

use of edu.iu.dsc.tws.comms.dfw.InMessage in project twister2 by DSC-SPIDAL.

the class KeyedSerializerTest method testBuildLargeListDoubleMessage.

@SuppressWarnings("Unchecked")
@Test
public void testBuildLargeListDoubleMessage() {
    int numBuffers = 32;
    int size = 1000;
    List<Object> data = new AggregatedObjects<>();
    for (int i = 0; i < 4; i++) {
        Object o = createKeyedData(800, MessageTypes.DOUBLE_ARRAY, MessageTypes.DOUBLE);
        data.add(o);
    }
    InMessage inMessage = keyedListValueCase(numBuffers, size, data, MessageTypes.DOUBLE_ARRAY, MessageTypes.DOUBLE);
    List<Object> result = (List<Object>) inMessage.getDeserializedData();
    for (int i = 0; i < result.size(); i++) {
        Tuple deserializedData = (Tuple) result.get(i);
        Tuple d = (Tuple) data.get(i);
        Assert.assertEquals((double) deserializedData.getKey(), (double) ((Tuple) d).getKey(), 0.1);
        Assert.assertArrayEquals((double[]) deserializedData.getValue(), (double[]) ((Tuple) d).getValue(), 0.01);
    }
}
Also used : InMessage(edu.iu.dsc.tws.comms.dfw.InMessage) List(java.util.List) Tuple(edu.iu.dsc.tws.api.comms.structs.Tuple) Test(org.junit.Test)

Example 19 with InMessage

use of edu.iu.dsc.tws.comms.dfw.InMessage in project twister2 by DSC-SPIDAL.

the class KeyedSerializerTest method testBuildLargeListLongMessage.

@SuppressWarnings("Unchecked")
@Test
public void testBuildLargeListLongMessage() {
    int numBuffers = 32;
    int size = 1000;
    List<Object> data = new AggregatedObjects<>();
    for (int i = 0; i < 4; i++) {
        Object o = createKeyedData(800, MessageTypes.LONG_ARRAY, MessageTypes.LONG);
        data.add(o);
    }
    InMessage inMessage = keyedListValueCase(numBuffers, size, data, MessageTypes.LONG_ARRAY, MessageTypes.LONG);
    List<Object> result = (List<Object>) inMessage.getDeserializedData();
    for (int i = 0; i < result.size(); i++) {
        Tuple deserializedData = (Tuple) result.get(i);
        Tuple d = (Tuple) data.get(i);
        Assert.assertEquals((long) deserializedData.getKey(), (long) ((Tuple) d).getKey(), 0.1);
        Assert.assertArrayEquals((long[]) deserializedData.getValue(), (long[]) ((Tuple) d).getValue());
    }
}
Also used : InMessage(edu.iu.dsc.tws.comms.dfw.InMessage) List(java.util.List) Tuple(edu.iu.dsc.tws.api.comms.structs.Tuple) Test(org.junit.Test)

Example 20 with InMessage

use of edu.iu.dsc.tws.comms.dfw.InMessage in project twister2 by DSC-SPIDAL.

the class KeyedSerializerTest method testBuildLargeListIntMessage.

@SuppressWarnings("Unchecked")
@Test
public void testBuildLargeListIntMessage() {
    int numBuffers = 16;
    int size = 1000;
    List<Object> data = new AggregatedObjects<>();
    for (int i = 0; i < 4; i++) {
        Object o = createKeyedData(800, MessageTypes.INTEGER_ARRAY, MessageTypes.INTEGER);
        data.add(o);
    }
    InMessage inMessage = keyedListValueCase(numBuffers, size, data, MessageTypes.INTEGER_ARRAY, MessageTypes.INTEGER);
    List<Object> result = (List<Object>) inMessage.getDeserializedData();
    for (int i = 0; i < result.size(); i++) {
        Tuple exp = (Tuple) result.get(i);
        Tuple d = (Tuple) data.get(i);
        Assert.assertEquals((int) exp.getKey(), (int) ((Tuple) d).getKey());
        Assert.assertArrayEquals((int[]) exp.getValue(), (int[]) ((Tuple) d).getValue());
    }
}
Also used : InMessage(edu.iu.dsc.tws.comms.dfw.InMessage) List(java.util.List) Tuple(edu.iu.dsc.tws.api.comms.structs.Tuple) Test(org.junit.Test)

Aggregations

InMessage (edu.iu.dsc.tws.comms.dfw.InMessage)38 Test (org.junit.Test)29 Tuple (edu.iu.dsc.tws.api.comms.structs.Tuple)17 ArrayList (java.util.ArrayList)17 MessageType (edu.iu.dsc.tws.api.comms.messaging.types.MessageType)15 List (java.util.List)14 ChannelMessage (edu.iu.dsc.tws.api.comms.messaging.ChannelMessage)10 MessageHeader (edu.iu.dsc.tws.api.comms.messaging.MessageHeader)10 DataBuffer (edu.iu.dsc.tws.api.comms.packing.DataBuffer)10 OutMessage (edu.iu.dsc.tws.comms.dfw.OutMessage)6 DataPacker (edu.iu.dsc.tws.api.comms.packing.DataPacker)4 ChannelListener (edu.iu.dsc.tws.api.comms.channel.ChannelListener)1 DataDeserializer (edu.iu.dsc.tws.comms.dfw.io.DataDeserializer)1 DataSerializer (edu.iu.dsc.tws.comms.dfw.io.DataSerializer)1 Queue (java.util.Queue)1 ConcurrentLinkedQueue (java.util.concurrent.ConcurrentLinkedQueue)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1