use of edu.iu.dsc.tws.comms.dfw.io.DataDeserializer in project twister2 by DSC-SPIDAL.
the class TWSUCXChannelTest method ucxTest.
@Test
public void ucxTest() throws InterruptedException {
final int dataSize = 25;
final int[] data = new int[dataSize];
for (int i = 0; i < dataSize; i++) {
data[i] = i;
}
new Thread(() -> {
TWSUCXChannel sender = new TWSUCXChannel(Config.newBuilder().build(), workerControllers.get(0));
OutMessage outMessage = new OutMessage(0, 1, -1, 10, 0, null, null, MessageTypes.INTEGER_ARRAY, null, null, data);
Queue<DataBuffer> sendingBuffers = new ConcurrentLinkedQueue<>();
sendingBuffers.add(new DataBuffer(sender.createBuffer(50)));
sendingBuffers.add(new DataBuffer(sender.createBuffer(50)));
DataSerializer dataSerializer = new DataSerializer();
dataSerializer.init(Config.newBuilder().build(), sendingBuffers);
AtomicInteger sendingCount = new AtomicInteger();
AtomicBoolean progress = new AtomicBoolean(true);
while (progress.get()) {
ChannelMessage channelMessage = dataSerializer.build(data, outMessage);
if (channelMessage != null) {
sender.sendMessage(1, channelMessage, new ChannelListener() {
@Override
public void onReceiveComplete(int id, int stream, DataBuffer message) {
}
@Override
public void onSendComplete(int id, int stream, ChannelMessage message) {
message.getBuffers().forEach(dataBuffer -> {
dataBuffer.setSize(0);
dataBuffer.getByteBuffer().clear();
});
sendingBuffers.addAll(message.getBuffers());
progress.set(!outMessage.getSendState().equals(OutMessage.SendState.SERIALIZED));
// LOG.info("Sending Count : " + sendingCount.incrementAndGet());
}
});
}
sender.progress();
}
LOG.info("Exiting send loop...");
}).start();
TWSUCXChannel receiver = new TWSUCXChannel(Config.newBuilder().build(), workerControllers.get(1));
Queue<DataBuffer> recvBuffers = new ConcurrentLinkedQueue<>();
recvBuffers.add(new DataBuffer(receiver.createBuffer(50)));
recvBuffers.add(new DataBuffer(receiver.createBuffer(50)));
DataDeserializer dataDeserializer = new DataDeserializer();
dataDeserializer.init(Config.newBuilder().build());
AtomicInteger recvCount = new AtomicInteger(0);
AtomicBoolean received = new AtomicBoolean(false);
final int[][] receivedData = new int[1][dataSize];
receiver.receiveMessage(0, 0, 1, new ChannelListener() {
private InMessage inMessage;
@Override
public void onReceiveComplete(int id, int stream, DataBuffer message) {
if (recvCount.incrementAndGet() == 1) {
MessageHeader messageHeader = dataDeserializer.buildHeader(message, 1);
this.inMessage = new InMessage(id, MessageTypes.INTEGER_ARRAY, channelMessage -> {
LOG.info("Release called");
}, messageHeader);
}
LOG.info("Received : " + recvCount.get());
if (this.inMessage.addBufferAndCalculate(message)) {
LOG.info("Built");
dataDeserializer.build(this.inMessage, 1);
receivedData[0] = (int[]) this.inMessage.getDataBuilder().getFinalObject();
received.set(true);
}
dataDeserializer.build(this.inMessage, 1);
message.getByteBuffer().clear();
recvBuffers.add(message);
}
@Override
public void onSendComplete(int id, int stream, ChannelMessage message) {
}
}, recvBuffers);
while (!received.get()) {
receiver.progress();
}
Assert.assertArrayEquals(data, receivedData[0]);
}
Aggregations