Search in sources :

Example 6 with InMessage

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

the class AggregatorListTest method testAggregatedObject.

@Test
public void testAggregatedObject() {
    int numBuffers = 16;
    int size = 1000;
    List<Object> data = new ArrayList<>();
    for (int i = 0; i < 4; i++) {
        data.add("I " + i);
    }
    Tuple tuple = new Tuple(1, data);
    InMessage inMessage = keyedSingleValueCase(numBuffers, size, MessageTypes.OBJECT, MessageTypes.INTEGER, tuple);
    Tuple result = (Tuple) inMessage.getDeserializedData();
    Assert.assertEquals((int) result.getKey(), 1);
    List<Object> resultList = (List<Object>) tuple.getValue();
    Assert.assertEquals(resultList, data);
}
Also used : ArrayList(java.util.ArrayList) InMessage(edu.iu.dsc.tws.comms.dfw.InMessage) List(java.util.List) ArrayList(java.util.ArrayList) Tuple(edu.iu.dsc.tws.api.comms.structs.Tuple) Test(org.junit.Test)

Example 7 with InMessage

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

the class DataSerializerTest method testBuildLargeDoubleMessage.

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

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

the class DataSerializerTest method singleValueCase.

private InMessage singleValueCase(int numBuffers, int size, MessageType type, Object data) {
    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 9 with InMessage

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

the class DataSerializerTest method testBuildLargeIntegerMessage.

@Test
public void testBuildLargeIntegerMessage() {
    int numBuffers = 10;
    int size = 1000;
    MessageType type = MessageTypes.INTEGER_ARRAY;
    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)

Example 10 with InMessage

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

the class DataSerializerTest method testBuildLargeByteMessage.

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