Search in sources :

Example 36 with InMessage

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

the class AggregatorListTest method testAggregatedList.

@Test
public void testAggregatedList() {
    int numBuffers = 16;
    int size = 1000;
    List<Object> tuples = new ArrayList<>();
    for (int j = 0; j < 10; j++) {
        List<Object> data = new ArrayList<>();
        for (int i = 0; i < 4; i++) {
            data.add("I " + i);
        }
        Tuple tuple = new Tuple(1, data);
        tuples.add(tuple);
    }
    try {
        InMessage inMessage = keyedListValueCase(numBuffers, size, tuples, MessageTypes.OBJECT, MessageTypes.INTEGER);
        Assert.fail();
    } catch (ClassCastException e) {
        Assert.assertTrue(true);
    }
    List<Object> aTuples = new AggregatedObjects<>();
    for (int j = 0; j < 10; j++) {
        List<Object> data = new ArrayList<>();
        for (int i = 0; i < 4; i++) {
            data.add("I " + i);
        }
        Tuple tuple = new Tuple(1, data);
        aTuples.add(tuple);
    }
    try {
        InMessage inMessage = keyedListValueCase(numBuffers, size, aTuples, MessageTypes.OBJECT, MessageTypes.INTEGER);
        Assert.assertTrue(true);
    } catch (ClassCastException e) {
        Assert.fail();
    }
}
Also used : ArrayList(java.util.ArrayList) InMessage(edu.iu.dsc.tws.comms.dfw.InMessage) Tuple(edu.iu.dsc.tws.api.comms.structs.Tuple) Test(org.junit.Test)

Example 37 with InMessage

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

the class DataSerializerTest method testBuildLargeShortMessage.

@Test
public void testBuildLargeShortMessage() {
    int numBuffers = 10;
    int size = 1000;
    MessageType type = MessageTypes.SHORT_ARRAY;
    Object data = createData(800, type);
    InMessage inMessage = singleValueCase(numBuffers, size, type, data);
    Assert.assertArrayEquals((short[]) inMessage.getDeserializedData(), (short[]) data);
}
Also used : InMessage(edu.iu.dsc.tws.comms.dfw.InMessage) MessageType(edu.iu.dsc.tws.api.comms.messaging.types.MessageType) Test(org.junit.Test)

Example 38 with InMessage

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

the class DataSerializerTest 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 = createData(800, MessageTypes.INTEGER_ARRAY);
        data.add(o);
    }
    InMessage inMessage = listValueCase(numBuffers, size, data, MessageTypes.INTEGER_ARRAY);
    List<Object> result = (List<Object>) inMessage.getDeserializedData();
    for (int i = 0; i < result.size(); i++) {
        Object exp = result.get(i);
        Object d = data.get(i);
        Assert.assertArrayEquals((int[]) exp, (int[]) d);
    }
}
Also used : InMessage(edu.iu.dsc.tws.comms.dfw.InMessage) ArrayList(java.util.ArrayList) List(java.util.List) 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