Search in sources :

Example 11 with InMessage

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

the class DataSerializerTest 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 = createData(800, MessageTypes.DOUBLE_ARRAY);
        data.add(o);
    }
    InMessage inMessage = listValueCase(numBuffers, size, data, MessageTypes.DOUBLE_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((double[]) exp, (double[]) d, 0.01);
    }
}
Also used : InMessage(edu.iu.dsc.tws.comms.dfw.InMessage) ArrayList(java.util.ArrayList) List(java.util.List) Test(org.junit.Test)

Example 12 with InMessage

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

the class DataSerializerTest method listValueCase.

private InMessage listValueCase(int numBuffers, int size, List<Object> data, MessageType type) {
    BlockingQueue<DataBuffer> bufferQueue = createDataQueue(numBuffers, size);
    OutMessage outMessage = new OutMessage(0, 1, -1, 10, 0, null, null, type, null, null, data);
    DataSerializer serializer = new DataSerializer();
    serializer.init(Config.newBuilder().build(), bufferQueue);
    List<ChannelMessage> messages = new ArrayList<>();
    while (outMessage.getSendState() != OutMessage.SendState.SERIALIZED) {
        ChannelMessage ch = serializer.build(data, outMessage);
        messages.add(ch);
    }
    DataDeserializer deserializer = new DataDeserializer();
    deserializer.init(Config.newBuilder().build());
    MessageHeader header = deserializer.buildHeader(messages.get(0).getBuffers().get(0), 1);
    InMessage inMessage = new InMessage(0, type, null, header);
    for (ChannelMessage channelMessage : messages) {
        for (DataBuffer dataBuffer : channelMessage.getBuffers()) {
            inMessage.addBufferAndCalculate(dataBuffer);
        }
    }
    deserializer.build(inMessage, 1);
    return inMessage;
}
Also used : OutMessage(edu.iu.dsc.tws.comms.dfw.OutMessage) ArrayList(java.util.ArrayList) InMessage(edu.iu.dsc.tws.comms.dfw.InMessage) MessageHeader(edu.iu.dsc.tws.api.comms.messaging.MessageHeader) DataBuffer(edu.iu.dsc.tws.api.comms.packing.DataBuffer) ChannelMessage(edu.iu.dsc.tws.api.comms.messaging.ChannelMessage)

Example 13 with InMessage

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

the class DataSerializerTest method testBuildLargeLongMessage.

@Test
public void testBuildLargeLongMessage() {
    int numBuffers = 10;
    int size = 1000;
    MessageType type = MessageTypes.LONG_ARRAY;
    Object data = createData(800, type);
    InMessage inMessage = singleValueCase(numBuffers, size, type, data);
    Assert.assertArrayEquals((long[]) inMessage.getDeserializedData(), (long[]) 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 14 with InMessage

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

the class DataSerializerTest 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 = createData(800, MessageTypes.LONG_ARRAY);
        data.add(o);
    }
    InMessage inMessage = listValueCase(numBuffers, size, data, MessageTypes.LONG_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((long[]) exp, (long[]) d);
    }
}
Also used : InMessage(edu.iu.dsc.tws.comms.dfw.InMessage) ArrayList(java.util.ArrayList) List(java.util.List) Test(org.junit.Test)

Example 15 with InMessage

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

the class DataSerializerTest method testBuildLargeObjectMessage.

@Test
public void testBuildLargeObjectMessage() {
    int numBuffers = 20;
    int size = 1000;
    MessageType type = MessageTypes.OBJECT;
    Object data = createData(800, type);
    InMessage inMessage = singleValueCase(numBuffers, size, type, data);
    Assert.assertArrayEquals((int[]) inMessage.getDeserializedData(), (int[]) 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)

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