use of org.apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder in project ignite by apache.
the class GridTcpSpiForwardingSelfTest method getConfiguration.
/**
* {@inheritDoc}
*/
@SuppressWarnings({ "IfMayBeConditional", "deprecation" })
@Override
protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
TcpDiscoveryVmIpFinder ipFinder = new TcpDiscoveryVmIpFinder();
if (ipFinderUseLocPorts)
ipFinder.setAddresses(Arrays.asList("127.0.0.1:" + locPort1, "127.0.0.1:" + locPort2));
else
ipFinder.setAddresses(Arrays.asList("127.0.0.1:" + extPort1, "127.0.0.1:" + extPort2));
TcpDiscoverySpi spi = new TcpDiscoverySpi();
final int locPort;
final int commLocPort;
if (getTestIgniteInstanceName(0).equals(igniteInstanceName)) {
locPort = locPort1;
commLocPort = commLocPort1;
} else if (getTestIgniteInstanceName(1).equals(igniteInstanceName)) {
locPort = locPort2;
commLocPort = commLocPort2;
} else
throw new IllegalArgumentException("Unknown Ignite instance name");
spi.setIpFinder(ipFinder);
IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName);
spi.setLocalPort(locPort);
spi.setLocalPortRange(1);
cfg.setDiscoverySpi(spi);
cfg.setLocalHost("127.0.0.1");
cfg.setConnectorConfiguration(null);
TcpCommunicationSpi commSpi = new TcpCommunicationSpi() {
@Override
protected GridCommunicationClient createTcpClient(ClusterNode node, int connIdx) throws IgniteCheckedException {
Map<String, Object> attrs = new HashMap<>(node.attributes());
attrs.remove(createSpiAttributeName(ATTR_PORT));
((TcpDiscoveryNode) node).setAttributes(attrs);
return super.createTcpClient(node, connIdx);
}
};
commSpi.setLocalAddress("127.0.0.1");
commSpi.setLocalPort(commLocPort);
commSpi.setLocalPortRange(1);
commSpi.setSharedMemoryPort(-1);
commSpi.setConnectionsPerNode(1);
cfg.setCommunicationSpi(commSpi);
assert rslvr != null;
cfg.setAddressResolver(rslvr);
return cfg;
}
use of org.apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder in project ignite by apache.
the class CacheTopologyCommandHandlerTest method getConfiguration.
/**
* {@inheritDoc}
*/
@Override
protected IgniteConfiguration getConfiguration() throws Exception {
// Discovery config.
TcpDiscoverySpi disco = new TcpDiscoverySpi().setIpFinder(new TcpDiscoveryVmIpFinder(true)).setJoinTimeout(5000);
// Cache config.
CacheConfiguration ccfg = new CacheConfiguration("cache*").setCacheMode(CacheMode.LOCAL).setAtomicityMode(CacheAtomicityMode.ATOMIC);
ConnectorConfiguration clnCfg = new ConnectorConfiguration().setHost("127.0.0.1");
return super.getConfiguration().setLocalHost("127.0.0.1").setConnectorConfiguration(clnCfg).setDiscoverySpi(disco).setCacheConfiguration(ccfg);
}
use of org.apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder in project ignite by apache.
the class GridCacheTcpClientDiscoveryMultiThreadedTest method getConfiguration.
/**
* {@inheritDoc}
*/
@Override
protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName);
// Filling configuration for client nodes
if (client) {
TcpDiscoveryVmIpFinder clientFinder = new TcpDiscoveryVmIpFinder();
Collection<String> addrs = new ArrayList<>(ipFinder.getRegisteredAddresses().size());
for (InetSocketAddress sockAddr : ipFinder.getRegisteredAddresses()) addrs.add(sockAddr.getHostString() + ":" + sockAddr.getPort());
clientFinder.setAddresses(addrs);
cfg.setDiscoverySpi(new TcpDiscoverySpi().setIpFinder(clientFinder));
cfg.setClientMode(true);
}
cfg.setLocalHost("127.0.0.1");
return cfg;
}
use of org.apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder in project ignite by apache.
the class TcpClientDiscoverySpiSelfTest method reconnectAfterSuspend.
/**
* @param changeTop If {@code true} topology is changed after client disconnects
* @throws Exception if failed.
*/
private void reconnectAfterSuspend(boolean changeTop) throws Exception {
reconnectCnt = 2;
startServerNodes(2);
Ignite srv0 = grid("server-0");
TcpDiscoveryNode srv0Node = (TcpDiscoveryNode) srv0.cluster().localNode();
TcpDiscoveryNode srv1Node = (TcpDiscoveryNode) grid("server-1").cluster().localNode();
clientIpFinder = new TcpDiscoveryVmIpFinder();
clientIpFinder.setAddresses(Collections.singleton("localhost:" + srv0Node.discoveryPort()));
startClientNodes(1);
Ignite client = grid("client-0");
TcpDiscoveryNode clientNode = (TcpDiscoveryNode) client.cluster().localNode();
TestTcpDiscoverySpi clientSpi = (TestTcpDiscoverySpi) client.configuration().getDiscoverySpi();
UUID clientNodeId = clientNode.id();
checkNodes(2, 1);
clientIpFinder.setAddresses(Collections.singleton("localhost:" + srv1Node.discoveryPort()));
srvFailedLatch = new CountDownLatch(1);
attachListeners(2, 1);
log.info("Pausing router");
TestTcpDiscoverySpi srvSpi = (TestTcpDiscoverySpi) srv0.configuration().getDiscoverySpi();
int joinedNodesNum = 3;
final CountDownLatch srvJoinedLatch = new CountDownLatch(joinedNodesNum);
if (changeTop) {
client.events().localListen(new IgnitePredicate<Event>() {
@Override
public boolean apply(Event e) {
srvJoinedLatch.countDown();
return true;
}
}, EVT_NODE_JOINED);
}
srvSpi.pauseAll(true);
if (changeTop)
startServerNodes(joinedNodesNum);
try {
await(srvFailedLatch, 60_000);
if (changeTop)
await(srvJoinedLatch, 5000);
assertEquals("connected", clientSpi.getSpiState());
assertEquals(clientNodeId, clientNode.id());
assertEquals(srv1Node.id(), clientNode.clientRouterNodeId());
} finally {
srvSpi.resumeAll();
}
}
use of org.apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder in project ignite by apache.
the class TcpClientDiscoverySpiSelfTest method missedAddFinishedMessage.
/**
* @param singleSrv If {@code true} starts one server node two otherwise.
* @throws Exception If failed.
*/
private void missedAddFinishedMessage(boolean singleSrv) throws Exception {
int srvs = singleSrv ? 1 : 2;
startServerNodes(srvs);
afterWrite = new CIX2<TcpDiscoveryAbstractMessage, Socket>() {
private boolean first = true;
@Override
public void applyx(TcpDiscoveryAbstractMessage msg, Socket sock) throws IgniteCheckedException {
if (first && (msg instanceof TcpDiscoveryJoinRequestMessage)) {
first = false;
log.info("Close socket after message write [msg=" + msg + "]");
try {
sock.close();
} catch (IOException e) {
throw new IgniteCheckedException(e);
}
log.info("Delay after message write [msg=" + msg + "]");
// Wait when server process join request.
U.sleep(5000);
}
}
};
Ignite srv = singleSrv ? G.ignite("server-0") : G.ignite("server-1");
TcpDiscoveryNode srvNode = (TcpDiscoveryNode) srv.cluster().localNode();
assertEquals(singleSrv ? 1 : 2, srvNode.order());
clientIpFinder = new TcpDiscoveryVmIpFinder();
clientIpFinder.setAddresses(Collections.singleton("localhost:" + srvNode.discoveryPort()));
startClientNodes(1);
TcpDiscoveryNode clientNode = (TcpDiscoveryNode) G.ignite("client-0").cluster().localNode();
assertEquals(srvNode.id(), clientNode.clientRouterNodeId());
checkNodes(srvs, 1);
}
Aggregations