use of org.apache.ignite.spi.communication.CommunicationSpi in project ignite by apache.
the class GridTcpCommunicationSpiAbstractTest method testCheckConnection2.
/**
* @throws Exception If failed.
*/
@Test
public void testCheckConnection2() throws Exception {
final int THREADS = spis.size();
final CyclicBarrier b = new CyclicBarrier(THREADS);
List<IgniteInternalFuture<?>> futs = new ArrayList<>();
for (Map.Entry<UUID, CommunicationSpi<Message>> entry : spis.entrySet()) {
final TcpCommunicationSpi spi = (TcpCommunicationSpi) entry.getValue();
futs.add(GridTestUtils.runAsync(new Callable<Void>() {
@Override
public Void call() throws Exception {
List<ClusterNode> checkNodes = new ArrayList<>(nodes);
assert checkNodes.size() > 1;
b.await();
for (int i = 0; i < 100; i++) {
IgniteFuture<BitSet> fut = spi.checkConnection(checkNodes);
BitSet res = fut.get();
for (int n = 0; n < checkNodes.size(); n++) assertTrue(res.get(n));
}
return null;
}
}));
}
for (IgniteInternalFuture<?> f : futs) f.get();
}
use of org.apache.ignite.spi.communication.CommunicationSpi in project ignite by apache.
the class ZookeeperDiscoverySpi method consistentId.
/**
* {@inheritDoc}
*/
@Nullable
@Override
public Serializable consistentId() throws IgniteSpiException {
if (consistentId == null) {
consistentId = ignite.configuration().getConsistentId();
if (consistentId == null) {
initAddresses();
final List<String> sortedAddrs = new ArrayList<>(addrs.get1());
Collections.sort(sortedAddrs);
if (getBoolean(IGNITE_CONSISTENT_ID_BY_HOST_WITHOUT_PORT))
consistentId = U.consistentId(sortedAddrs);
else {
Integer commPort = null;
if (locNodeAttrs != null) {
commPort = (Integer) locNodeAttrs.get(TcpCommunicationSpi.class.getSimpleName() + "." + TcpCommunicationSpi.ATTR_PORT);
} else {
CommunicationSpi commSpi = ignite.configuration().getCommunicationSpi();
if (commSpi instanceof TcpCommunicationSpi) {
commPort = ((TcpCommunicationSpi) commSpi).boundPort();
if (commPort == -1)
commPort = null;
}
}
if (commPort == null) {
U.warn(log, "Can not initialize default consistentId, TcpCommunicationSpi port is not initialized.");
consistentId = ignite.configuration().getNodeId();
} else
consistentId = U.consistentId(sortedAddrs, commPort);
}
}
}
return consistentId;
}
use of org.apache.ignite.spi.communication.CommunicationSpi in project ignite by apache.
the class GridTcpCommunicationSpiMultithreadedSelfTest method beforeTestsStarted.
/**
* {@inheritDoc}
*/
@Override
protected void beforeTestsStarted() throws Exception {
spis.clear();
nodes.clear();
spiRsrcs.clear();
lsnrs.clear();
Map<ClusterNode, GridSpiTestContext> ctxs = new HashMap<>();
timeoutProcessor = new GridTimeoutProcessor(new GridTestKernalContext(log));
timeoutProcessor.start();
timeoutProcessor.onKernalStart(true);
for (int i = 0; i < getSpiCount(); i++) {
CommunicationSpi<Message> spi = newCommunicationSpi();
GridTestUtils.setFieldValue(spi, IgniteSpiAdapter.class, "igniteInstanceName", "grid-" + i);
IgniteTestResources rsrcs = new IgniteTestResources();
GridTestNode node = new GridTestNode(rsrcs.getNodeId());
node.order(i);
GridSpiTestContext ctx = initSpiContext();
MessageFactoryProvider testMsgFactory = factory -> factory.register(GridTestMessage.DIRECT_TYPE, GridTestMessage::new);
ctx.messageFactory(new IgniteMessageFactoryImpl(new MessageFactory[] { new GridIoMessageFactory(), testMsgFactory }));
ctx.timeoutProcessor(timeoutProcessor);
ctx.setLocalNode(node);
info(">>> Initialized context: nodeId=" + ctx.localNode().id());
spiRsrcs.add(rsrcs);
rsrcs.inject(spi);
MessageListener lsnr = new MessageListener(rsrcs.getNodeId());
spi.setListener(lsnr);
lsnrs.put(rsrcs.getNodeId(), lsnr);
info("Lsnrs: " + lsnrs);
spi.spiStart(getTestIgniteInstanceName() + (i + 1));
nodes.add(node);
node.setAttributes(spi.getNodeAttributes());
node.setAttribute(ATTR_MACS, F.concat(U.allLocalMACs(), ", "));
spis.put(rsrcs.getNodeId(), spi);
spi.onContextInitialized(ctx);
ctxs.put(node, ctx);
}
// For each context set remote nodes.
for (Entry<ClusterNode, GridSpiTestContext> e : ctxs.entrySet()) {
for (ClusterNode n : nodes) {
if (!n.equals(e.getKey()))
e.getValue().remoteNodes().add(n);
}
}
}
use of org.apache.ignite.spi.communication.CommunicationSpi in project ignite by apache.
the class IgniteCachePartitionedQuerySelfTest method testScanQueryPagination.
/**
* @throws Exception If failed.
*/
@Test
public void testScanQueryPagination() throws Exception {
final int pageSize = 5;
final AtomicInteger pages = new AtomicInteger(0);
IgniteCache<Integer, Integer> cache = jcache(Integer.class, Integer.class);
for (int i = 0; i < 50; i++) cache.put(i, i);
CommunicationSpi spi = ignite().configuration().getCommunicationSpi();
assert spi instanceof TestTcpCommunicationSpi;
TestTcpCommunicationSpi commSpi = (TestTcpCommunicationSpi) spi;
commSpi.filter = new IgniteInClosure<Message>() {
@Override
public void apply(Message msg) {
if (!(msg instanceof GridIoMessage))
return;
Message msg0 = ((GridIoMessage) msg).message();
if (msg0 instanceof GridCacheQueryRequest) {
assertEquals(pageSize, ((GridCacheQueryRequest) msg0).pageSize());
pages.incrementAndGet();
} else if (msg0 instanceof GridCacheQueryResponse)
assertTrue(((GridCacheQueryResponse) msg0).data().size() <= pageSize);
}
};
try {
ScanQuery<Integer, Integer> qry = new ScanQuery<Integer, Integer>();
qry.setPageSize(pageSize);
List<Cache.Entry<Integer, Integer>> all = cache.query(qry).getAll();
assertTrue(pages.get() > ignite().cluster().forDataNodes(DEFAULT_CACHE_NAME).nodes().size());
assertEquals(50, all.size());
} finally {
commSpi.filter = null;
}
}
Aggregations