use of org.apache.ignite.events.DiscoveryEvent in project ignite by apache.
the class GridSpiTestContext method resetNodes.
/**
* @param nodes Nodes to reset.
* @param rmv Whether nodes that were not passed in should be removed or not.
*/
public void resetNodes(Collection<ClusterNode> nodes, boolean rmv) {
for (ClusterNode node : nodes) {
assert !node.equals(locNode);
if (!rmtNodes.contains(node))
addNode(node);
}
if (rmv) {
for (Iterator<ClusterNode> iter = rmtNodes.iterator(); iter.hasNext(); ) {
ClusterNode node = iter.next();
if (!nodes.contains(node)) {
iter.remove();
notifyListener(new DiscoveryEvent(locNode, "Node left", EVT_NODE_LEFT, node));
}
}
}
}
use of org.apache.ignite.events.DiscoveryEvent in project ignite by apache.
the class GridSpiTestContext method addNode.
/**
* @param node Node to add.
*/
public void addNode(ClusterNode node) {
rmtNodes.add(node);
notifyListener(new DiscoveryEvent(locNode, "Node joined", EVT_NODE_JOINED, node));
}
use of org.apache.ignite.events.DiscoveryEvent in project ignite by apache.
the class ZookeeperDiscoverySegmentationAndConnectionRestoreTest method connectionRestore_Coordinator.
/**
* @param initNodes Number of initially started nodes.
* @param startNodes Number of nodes to start after coordinator loose connection.
* @param failCnt Number of nodes to stop after coordinator loose connection.
* @throws Exception If failed.
*/
private void connectionRestore_Coordinator(final int initNodes, int startNodes, int failCnt) throws Exception {
sesTimeout = 30_000;
testSockNio = true;
Ignite node0 = startGrids(initNodes);
ZkTestClientCnxnSocketNIO c0 = ZkTestClientCnxnSocketNIO.forNode(node0);
c0.closeSocket(true);
final AtomicInteger nodeIdx = new AtomicInteger(initNodes);
IgniteInternalFuture<?> fut = GridTestUtils.runMultiThreadedAsync(new Callable<Void>() {
@Override
public Void call() {
try {
startGrid(nodeIdx.getAndIncrement());
} catch (Exception e) {
error("Start failed: " + e);
}
return null;
}
}, startNodes, "start-node");
int cnt = 0;
DiscoveryEvent[] expEvts = new DiscoveryEvent[startNodes - failCnt];
int expEvtCnt = 0;
sesTimeout = 1000;
List<ZkTestClientCnxnSocketNIO> blockedC = new ArrayList<>();
final List<String> failedZkNodes = new ArrayList<>(failCnt);
for (int i = initNodes; i < initNodes + startNodes; i++) {
final ZookeeperDiscoverySpi spi = helper.waitSpi(getTestIgniteInstanceName(i), spis);
assertTrue(GridTestUtils.waitForCondition(new GridAbsPredicate() {
@Override
public boolean apply() {
Object spiImpl = GridTestUtils.getFieldValue(spi, "impl");
if (spiImpl == null)
return false;
long internalOrder = GridTestUtils.getFieldValue(spiImpl, "rtState", "internalOrder");
return internalOrder > 0;
}
}, 10_000));
if (cnt++ < failCnt) {
ZkTestClientCnxnSocketNIO c = ZkTestClientCnxnSocketNIO.forNode(getTestIgniteInstanceName(i));
c.closeSocket(true);
blockedC.add(c);
failedZkNodes.add(ZookeeperDiscoverySpiTestHelper.aliveZkNodePath(spi));
} else {
expEvts[expEvtCnt] = ZookeeperDiscoverySpiTestHelper.joinEvent(initNodes + expEvtCnt + 1);
expEvtCnt++;
}
}
ZookeeperDiscoverySpiTestHelper.waitNoAliveZkNodes(log, zkCluster.getConnectString(), failedZkNodes, 30_000);
c0.allowConnect();
for (ZkTestClientCnxnSocketNIO c : blockedC) c.allowConnect();
if (expEvts.length > 0) {
for (int i = 0; i < initNodes; i++) helper.checkEvents(ignite(i), evts, expEvts);
}
fut.get();
waitForTopology(initNodes + startNodes - failCnt);
}
use of org.apache.ignite.events.DiscoveryEvent in project ignite by apache.
the class ZookeeperDiscoverySpiTestHelper method leftEvent.
/**
* @param topVer Topology version.
* @return Expected event instance.
*/
static DiscoveryEvent leftEvent(long topVer, boolean fail) {
int eventType = fail ? EventType.EVT_NODE_FAILED : EventType.EVT_NODE_LEFT;
DiscoveryEvent expEvt = new DiscoveryEvent(null, null, eventType, null);
expEvt.topologySnapshot(topVer, null);
return expEvt;
}
use of org.apache.ignite.events.DiscoveryEvent in project ignite by apache.
the class ZookeeperDiscoverySpiTestHelper method checkEvents.
/**
* @param nodeId Node ID.
* @param expEvts Expected events.
* @throws Exception If failed.
*/
private void checkEvents(final UUID nodeId, ConcurrentHashMap<UUID, Map<T2<Integer, Long>, DiscoveryEvent>> evts, final DiscoveryEvent... expEvts) throws Exception {
Assert.assertTrue(GridTestUtils.waitForCondition(new GridAbsPredicate() {
@SuppressWarnings("SynchronizationOnLocalVariableOrMethodParameter")
@Override
public boolean apply() {
Map<T2<Integer, Long>, DiscoveryEvent> nodeEvts = evts.get(nodeId);
if (nodeEvts == null) {
info.accept("No events for node: " + nodeId);
return false;
}
synchronized (nodeEvts) {
for (DiscoveryEvent expEvt : expEvts) {
DiscoveryEvent evt0 = nodeEvts.get(new T2<>(clusterNum.get(), expEvt.topologyVersion()));
if (evt0 == null) {
info.accept("No event for version: " + expEvt.topologyVersion());
return false;
}
Assert.assertEquals(// todo check
"Unexpected event [topVer=" + expEvt.topologyVersion() + ", exp=" + U.gridEventName(expEvt.type()) + ", evt=" + evt0 + ']', expEvt.type(), evt0.type());
}
}
return true;
}
}, 30000));
}
Aggregations