use of org.apache.ignite.testframework.GridTestNode in project ignite by apache.
the class GridTcpCommunicationSpiRecoverySelfTest method startSpis.
/**
* @throws Exception If failed.
*/
private void startSpis() throws Exception {
spis.clear();
nodes.clear();
spiRsrcs.clear();
Map<ClusterNode, GridSpiTestContext> ctxs = new HashMap<>();
for (int i = 0; i < SPI_CNT; i++) {
TcpCommunicationSpi spi = getSpi(i);
GridTestUtils.setFieldValue(spi, IgniteSpiAdapter.class, "igniteInstanceName", "grid-" + i);
IgniteTestResources rsrcs = new IgniteTestResources();
GridTestNode node = new GridTestNode(rsrcs.getNodeId());
node.order(i);
GridSpiTestContext ctx = initSpiContext();
ctx.setLocalNode(node);
spiRsrcs.add(rsrcs);
rsrcs.inject(spi);
if (useSsl) {
IgniteMock ignite = GridTestUtils.getFieldValue(spi, IgniteSpiAdapter.class, "ignite");
IgniteConfiguration cfg = ignite.configuration().setSslContextFactory(GridTestUtils.sslFactory());
ignite.setStaticCfg(cfg);
}
spi.setListener(new TestListener());
node.setAttributes(spi.getNodeAttributes());
nodes.add(node);
spi.spiStart(getTestIgniteInstanceName() + (i + 1));
spis.add(spi);
spi.onContextInitialized(ctx);
ctxs.put(node, ctx);
}
// For each context set remote nodes.
for (Map.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.testframework.GridTestNode in project ignite by apache.
the class IgniteTcpCommunicationRecoveryAckClosureSelfTest method startSpis.
/**
* @param ackCnt Recovery acknowledgement count.
* @param idleTimeout Idle connection timeout.
* @param queueLimit Message queue limit.
* @throws Exception If failed.
*/
private void startSpis(int ackCnt, int idleTimeout, int queueLimit) throws Exception {
spis.clear();
nodes.clear();
spiRsrcs.clear();
Map<ClusterNode, GridSpiTestContext> ctxs = new HashMap<>();
for (int i = 0; i < SPI_CNT; i++) {
TcpCommunicationSpi spi = getSpi(ackCnt, idleTimeout, queueLimit);
GridTestUtils.setFieldValue(spi, IgniteSpiAdapter.class, "igniteInstanceName", "grid-" + i);
IgniteTestResources rsrcs = new IgniteTestResources();
GridTestNode node = new GridTestNode(rsrcs.getNodeId());
GridSpiTestContext ctx = initSpiContext();
ctx.setLocalNode(node);
spiRsrcs.add(rsrcs);
rsrcs.inject(spi);
spi.setListener(new TestListener());
node.setAttributes(spi.getNodeAttributes());
nodes.add(node);
spi.spiStart(getTestIgniteInstanceName() + (i + 1));
spis.add(spi);
spi.onContextInitialized(ctx);
ctxs.put(node, ctx);
}
// For each context set remote nodes.
for (Map.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.testframework.GridTestNode in project ignite by apache.
the class GridSpiAbstractTest method initSpiContext.
/**
* @return SPI context.
* @throws Exception If anything failed.
*/
protected GridSpiTestContext initSpiContext() throws Exception {
GridSpiTestContext spiCtx = new GridSpiTestContext();
if (getTestData().getDiscoverySpi() != null) {
spiCtx.setLocalNode(getTestData().getDiscoverySpi().getLocalNode());
for (ClusterNode node : getTestData().getDiscoverySpi().getRemoteNodes()) spiCtx.addNode(node);
} else {
GridTestNode node = new GridTestNode(UUID.randomUUID());
spiCtx.setLocalNode(node);
if (getSpi() != null) {
// Set up SPI class name and SPI version.
Map<String, Serializable> attrs = initSpiClassAndVersionAttributes(getSpi());
for (Map.Entry<String, Serializable> entry : attrs.entrySet()) node.addAttribute(entry.getKey(), entry.getValue());
}
}
return spiCtx;
}
use of org.apache.ignite.testframework.GridTestNode in project ignite by apache.
the class GridCommonAbstractTest method movingKeysAfterJoin.
/**
* Return list of keys that are primary for given node on current topology,
* but primary node will change after new node will be added.
*
* @param ign Ignite.
* @param cacheName Cache name.
* @param size Number of keys.
* @return List of keys.
*/
protected final List<Integer> movingKeysAfterJoin(Ignite ign, String cacheName, int size) {
assertEquals("Expected consistentId is set to node name", ign.name(), ign.cluster().localNode().consistentId());
GridCacheContext<Object, Object> cctx = ((IgniteKernal) ign).context().cache().internalCache(cacheName).context();
ArrayList<ClusterNode> nodes = new ArrayList<>(ign.cluster().nodes());
AffinityFunction func = cctx.config().getAffinity();
AffinityFunctionContext ctx = new GridAffinityFunctionContextImpl(nodes, null, null, AffinityTopologyVersion.NONE, cctx.config().getBackups());
List<List<ClusterNode>> calcAff = func.assignPartitions(ctx);
GridTestNode fakeNode = new GridTestNode(UUID.randomUUID(), null);
fakeNode.consistentId(getTestIgniteInstanceName(nodes.size()));
nodes.add(fakeNode);
ctx = new GridAffinityFunctionContextImpl(nodes, null, null, AffinityTopologyVersion.NONE, cctx.config().getBackups());
List<List<ClusterNode>> calcAff2 = func.assignPartitions(ctx);
Set<Integer> movedParts = new HashSet<>();
UUID locId = ign.cluster().localNode().id();
for (int i = 0; i < calcAff.size(); i++) {
if (calcAff.get(i).get(0).id().equals(locId) && !calcAff2.get(i).get(0).id().equals(locId))
movedParts.add(i);
}
List<Integer> keys = new ArrayList<>();
Affinity<Integer> aff = ign.affinity(cacheName);
for (int i = 0; i < 10_000; i++) {
int keyPart = aff.partition(i);
if (movedParts.contains(keyPart)) {
keys.add(i);
if (keys.size() == size)
break;
}
}
assertEquals("Failed to find moving keys [movedPats=" + movedParts + ", keys=" + keys + ']', size, keys.size());
return keys;
}
use of org.apache.ignite.testframework.GridTestNode in project ignite by apache.
the class GridAbstractCommunicationSelfTest method startSpis.
/**
* @throws Exception If failed.
*/
private void startSpis() throws Exception {
spis.clear();
nodes.clear();
spiRsrcs.clear();
Map<ClusterNode, GridSpiTestContext> ctxs = new HashMap<>();
for (int i = 0; i < getSpiCount(); i++) {
CommunicationSpi<Message> spi = getSpi(i);
GridTestUtils.setFieldValue(spi, IgniteSpiAdapter.class, "igniteInstanceName", "grid-" + i);
IgniteTestResources rsrcs = new IgniteTestResources();
GridTestNode node = new GridTestNode(rsrcs.getNodeId());
node.order(i);
GridSpiTestContext ctx = initSpiContext();
ctx.setLocalNode(node);
info(">>> Initialized context: nodeId=" + ctx.localNode().id());
spiRsrcs.add(rsrcs);
rsrcs.inject(spi);
if (useSsl) {
IgniteMock ignite = GridTestUtils.getFieldValue(spi, IgniteSpiAdapter.class, "ignite");
IgniteConfiguration cfg = ignite.configuration().setSslContextFactory(GridTestUtils.sslFactory());
ignite.setStaticCfg(cfg);
}
spi.setListener(new MessageListener(rsrcs.getNodeId()));
node.setAttributes(spi.getNodeAttributes());
node.setAttribute(ATTR_MACS, F.concat(U.allLocalMACs(), ", "));
nodes.add(node);
spi.spiStart(getTestIgniteInstanceName() + (i + 1));
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);
}
}
}
Aggregations