use of org.apache.ignite.internal.direct.DirectMessageWriter in project ignite by apache.
the class GridLongListSelfTest method testSerializationCopyConstructor.
/**
*/
@Test
public void testSerializationCopyConstructor() {
MessageWriter writer = new DirectMessageWriter(GridIoManager.DIRECT_PROTO_VER);
ByteBuffer buf = ByteBuffer.allocate(4096);
GridLongList ll = new GridLongList(new long[] { 1L, 2L, 3L });
{
Assert.assertTrue(ll.writeTo(buf, writer));
Assert.assertEquals(HEADER_SIZE + 25 + /* array */
1, /* index */
buf.position());
}
{
writer.reset();
buf.clear();
ll.add(2L);
ll.add(4L);
Assert.assertTrue(ll.writeTo(buf, writer));
Assert.assertEquals(HEADER_SIZE + 41 + /* array */
1, /* index */
buf.position());
}
{
writer.reset();
buf.clear();
ll.remove();
Assert.assertTrue(ll.writeTo(buf, writer));
Assert.assertEquals(HEADER_SIZE + 33 + /* array */
1, /* index */
buf.position());
}
{
writer.reset();
buf.clear();
for (int i = 0; i < 300; i++) ll.add(i);
Assert.assertTrue(ll.writeTo(buf, writer));
Assert.assertEquals(HEADER_SIZE + 2434 + /* array */
2, /* index */
buf.position());
}
{
writer.reset();
buf.clear();
ll.clear();
Assert.assertTrue(ll.writeTo(buf, writer));
Assert.assertEquals(HEADER_SIZE + 1 + /* array */
1, /* index */
buf.position());
}
}
use of org.apache.ignite.internal.direct.DirectMessageWriter in project ignite by apache.
the class GridLongListSelfTest method testSerializationDefaultConstructor.
/**
*/
@Test
public void testSerializationDefaultConstructor() {
MessageWriter writer = new DirectMessageWriter(GridIoManager.DIRECT_PROTO_VER);
ByteBuffer buf = ByteBuffer.allocate(4096);
GridLongList ll = new GridLongList();
{
Assert.assertTrue(ll.writeTo(buf, writer));
Assert.assertEquals(HEADER_SIZE + 1 + /* array */
1, /* index */
buf.position());
}
{
writer.reset();
buf.clear();
ll.add(2L);
ll.add(4L);
Assert.assertTrue(ll.writeTo(buf, writer));
Assert.assertEquals(HEADER_SIZE + 17 + /* array */
1, /* index */
buf.position());
}
{
writer.reset();
buf.clear();
ll.remove();
Assert.assertTrue(ll.writeTo(buf, writer));
Assert.assertEquals(HEADER_SIZE + 9 + /* array */
1, /* index */
buf.position());
}
{
writer.reset();
buf.clear();
ll.remove();
Assert.assertTrue(ll.writeTo(buf, writer));
Assert.assertEquals(HEADER_SIZE + 1 + /* array */
1, /* index */
buf.position());
}
{
writer.reset();
buf.clear();
for (int i = 0; i < 300; i++) ll.add(i);
Assert.assertTrue(ll.writeTo(buf, writer));
Assert.assertEquals(300, ll.size());
Assert.assertEquals(HEADER_SIZE + 2402 + /* array */
2, /* index */
buf.position());
}
{
writer.reset();
buf.clear();
ll.clear();
Assert.assertTrue(ll.writeTo(buf, writer));
Assert.assertEquals(HEADER_SIZE + 1 + /* array */
1, /* index */
buf.position());
}
}
use of org.apache.ignite.internal.direct.DirectMessageWriter in project ignite by apache.
the class GridLongListSelfTest method testSerializationConstructorWithZeroSize.
/**
*/
@Ignore("https://issues.apache.org/jira/browse/IGNITE-12678")
@Test
public void testSerializationConstructorWithZeroSize() {
MessageWriter writer = new DirectMessageWriter(GridIoManager.DIRECT_PROTO_VER);
ByteBuffer buf = ByteBuffer.allocate(4096);
GridLongList ll = new GridLongList(0);
{
Assert.assertTrue(ll.writeTo(buf, writer));
Assert.assertEquals(HEADER_SIZE + 1 + /* array */
1, /* index */
buf.position());
}
{
writer.reset();
buf.clear();
ll.add(2L);
ll.add(4L);
Assert.assertTrue(ll.writeTo(buf, writer));
Assert.assertEquals(HEADER_SIZE + 17 + /* array */
1, /* index */
buf.position());
}
{
writer.reset();
buf.clear();
ll.remove();
Assert.assertTrue(ll.writeTo(buf, writer));
Assert.assertEquals(HEADER_SIZE + 9 + /* array */
1, /* index */
buf.position());
}
{
writer.reset();
buf.clear();
ll.remove();
Assert.assertTrue(ll.writeTo(buf, writer));
Assert.assertEquals(HEADER_SIZE + 1 + /* array */
1, /* index */
buf.position());
}
{
writer.reset();
buf.clear();
for (int i = 0; i < 300; i++) ll.add(i);
Assert.assertTrue(ll.writeTo(buf, writer));
Assert.assertEquals(300, ll.size());
Assert.assertEquals(HEADER_SIZE + 2402 + /* array */
2, /* index */
buf.position());
}
{
writer.reset();
buf.clear();
ll.clear();
Assert.assertTrue(ll.writeTo(buf, writer));
Assert.assertEquals(HEADER_SIZE + 1 + /* array */
1, /* index */
buf.position());
}
}
use of org.apache.ignite.internal.direct.DirectMessageWriter in project ignite by apache.
the class GridLongListSelfTest method testSerializationConstructorWithSize.
/**
*/
@Test
public void testSerializationConstructorWithSize() {
MessageWriter writer = new DirectMessageWriter(GridIoManager.DIRECT_PROTO_VER);
ByteBuffer buf = ByteBuffer.allocate(4096);
GridLongList ll = new GridLongList(5);
{
Assert.assertTrue(ll.writeTo(buf, writer));
Assert.assertEquals(HEADER_SIZE + 1 + /* array */
1, /* index */
buf.position());
}
{
writer.reset();
buf.clear();
ll.add(2L);
ll.add(4L);
Assert.assertTrue(ll.writeTo(buf, writer));
Assert.assertEquals(HEADER_SIZE + 17 + /* array */
1, /* index */
buf.position());
}
{
writer.reset();
buf.clear();
ll.remove();
Assert.assertTrue(ll.writeTo(buf, writer));
Assert.assertEquals(HEADER_SIZE + 9 + /* array */
1, /* index */
buf.position());
}
{
writer.reset();
buf.clear();
ll.remove();
Assert.assertTrue(ll.writeTo(buf, writer));
Assert.assertEquals(HEADER_SIZE + 1 + /* array */
1, /* index */
buf.position());
}
{
writer.reset();
buf.clear();
for (int i = 0; i < 300; i++) ll.add(i);
Assert.assertTrue(ll.writeTo(buf, writer));
Assert.assertEquals(300, ll.size());
Assert.assertEquals(HEADER_SIZE + 2402 + /* array */
2, /* index */
buf.position());
}
{
writer.reset();
buf.clear();
ll.clear();
Assert.assertTrue(ll.writeTo(buf, writer));
Assert.assertEquals(HEADER_SIZE + 1 + /* array */
1, /* index */
buf.position());
}
}
use of org.apache.ignite.internal.direct.DirectMessageWriter in project ignite by apache.
the class GridIoManager method start.
/** {@inheritDoc} */
@SuppressWarnings("deprecation")
@Override
public void start(boolean activeOnStart) throws IgniteCheckedException {
assertParameter(discoDelay > 0, "discoveryStartupDelay > 0");
startSpi();
getSpi().setListener(commLsnr = new CommunicationListener<Serializable>() {
@Override
public void onMessage(UUID nodeId, Serializable msg, IgniteRunnable msgC) {
try {
onMessage0(nodeId, (GridIoMessage) msg, msgC);
} catch (ClassCastException ignored) {
U.error(log, "Communication manager received message of unknown type (will ignore): " + msg.getClass().getName() + ". Most likely GridCommunicationSpi is being used directly, " + "which is illegal - make sure to send messages only via GridProjection API.");
}
}
@Override
public void onDisconnected(UUID nodeId) {
for (GridDisconnectListener lsnr : disconnectLsnrs) lsnr.onNodeDisconnected(nodeId);
}
});
ctx.addNodeAttribute(DIRECT_PROTO_VER_ATTR, DIRECT_PROTO_VER);
MessageFormatter[] formatterExt = ctx.plugins().extensions(MessageFormatter.class);
if (formatterExt != null && formatterExt.length > 0) {
if (formatterExt.length > 1)
throw new IgniteCheckedException("More than one MessageFormatter extension is defined. Check your " + "plugins configuration and make sure that only one of them provides custom message format.");
formatter = formatterExt[0];
} else {
formatter = new MessageFormatter() {
@Override
public MessageWriter writer(UUID rmtNodeId) throws IgniteCheckedException {
assert rmtNodeId != null;
return new DirectMessageWriter(U.directProtocolVersion(ctx, rmtNodeId));
}
@Override
public MessageReader reader(UUID rmtNodeId, MessageFactory msgFactory) throws IgniteCheckedException {
assert rmtNodeId != null;
return new DirectMessageReader(msgFactory, U.directProtocolVersion(ctx, rmtNodeId));
}
};
}
MessageFactory[] msgs = ctx.plugins().extensions(MessageFactory.class);
if (msgs == null)
msgs = EMPTY;
List<MessageFactory> compMsgs = new ArrayList<>();
for (IgniteComponentType compType : IgniteComponentType.values()) {
MessageFactory f = compType.messageFactory();
if (f != null)
compMsgs.add(f);
}
if (!compMsgs.isEmpty())
msgs = F.concat(msgs, compMsgs.toArray(new MessageFactory[compMsgs.size()]));
msgFactory = new GridIoMessageFactory(msgs);
if (log.isDebugEnabled())
log.debug(startInfo());
addMessageListener(GridTopic.TOPIC_IO_TEST, new GridMessageListener() {
@Override
public void onMessage(UUID nodeId, Object msg) {
ClusterNode node = ctx.discovery().node(nodeId);
if (node == null)
return;
IgniteIoTestMessage msg0 = (IgniteIoTestMessage) msg;
msg0.senderNodeId(nodeId);
if (msg0.request()) {
IgniteIoTestMessage res = new IgniteIoTestMessage(msg0.id(), false, null);
res.flags(msg0.flags());
res.onRequestProcessed();
res.copyDataFromRequest(msg0);
try {
sendToGridTopic(node, GridTopic.TOPIC_IO_TEST, res, GridIoPolicy.SYSTEM_POOL);
} catch (IgniteCheckedException e) {
U.error(log, "Failed to send IO test response [msg=" + msg0 + "]", e);
}
} else {
IoTestFuture fut = ioTestMap().get(msg0.id());
msg0.onResponseProcessed();
if (fut == null)
U.warn(log, "Failed to find IO test future [msg=" + msg0 + ']');
else
fut.onResponse(msg0);
}
}
});
}
Aggregations