use of org.apache.ignite.testframework.junits.IgniteTestResources in project ignite by apache.
the class IgfsSharedMemoryTestServer method main.
@SuppressWarnings({ "BusyWait", "InfiniteLoopStatement" })
public static void main(String[] args) throws IgniteCheckedException {
System.out.println("Starting server ...");
// Tell our process PID to the wrapper.
X.println(GridJavaProcess.PID_MSG_PREFIX + U.jvmPid());
InputStream is = null;
try {
IpcServerEndpoint srv = new IpcSharedMemoryServerEndpoint(U.defaultWorkDirectory());
new IgniteTestResources().inject(srv);
srv.start();
System.out.println("IPC shared memory server endpoint started");
IpcEndpoint clientEndpoint = srv.accept();
is = clientEndpoint.inputStream();
for (; ; ) {
X.println("Before read.");
is.read();
Thread.sleep(IpcSharedMemoryCrashDetectionSelfTest.RW_SLEEP_TIMEOUT);
}
} catch (Exception e) {
e.printStackTrace();
} finally {
U.closeQuiet(is);
}
}
use of org.apache.ignite.testframework.junits.IgniteTestResources in project ignite by apache.
the class IpcSharedMemoryCrashDetectionSelfTest method afterTestsStopped.
/**
* {@inheritDoc}
*/
@Override
protected void afterTestsStopped() throws Exception {
// Start and stop server endpoint to let GC worker
// make a run and cleanup resources.
IpcSharedMemoryServerEndpoint srv = new IpcSharedMemoryServerEndpoint(U.defaultWorkDirectory());
new IgniteTestResources().inject(srv);
try {
srv.start();
} finally {
srv.close();
}
}
use of org.apache.ignite.testframework.junits.IgniteTestResources in project ignite by apache.
the class IpcSharedMemoryCrashDetectionSelfTest method testIgfsServerClientInteractionsUponClientKilling.
/**
* @throws Exception If failed.
*/
public void testIgfsServerClientInteractionsUponClientKilling() throws Exception {
// Run server endpoint.
IpcSharedMemoryServerEndpoint srv = new IpcSharedMemoryServerEndpoint(U.defaultWorkDirectory());
new IgniteTestResources().inject(srv);
try {
srv.start();
info("Check that server gets correct exception upon client's killing.");
info("Shared memory IDs before starting client endpoint: " + IpcSharedMemoryUtils.sharedMemoryIds());
Collection<Integer> shmemIdsWithinInteractions = interactWithClient(srv, true);
Collection<Integer> shmemIdsAfterInteractions = null;
// Give server endpoint some time to make resource clean up. See IpcSharedMemoryServerEndpoint.GC_FREQ.
for (int i = 0; i < 12; i++) {
shmemIdsAfterInteractions = IpcSharedMemoryUtils.sharedMemoryIds();
info("Shared memory IDs created within interaction: " + shmemIdsWithinInteractions);
info("Shared memory IDs after killing client endpoint: " + shmemIdsAfterInteractions);
if (CollectionUtils.containsAny(shmemIdsAfterInteractions, shmemIdsWithinInteractions))
U.sleep(1000);
else
break;
}
assertFalse("List of shared memory IDs after killing client endpoint should not include IDs created " + "within server-client interactions.", CollectionUtils.containsAny(shmemIdsAfterInteractions, shmemIdsWithinInteractions));
} finally {
srv.close();
}
}
use of org.apache.ignite.testframework.junits.IgniteTestResources in project ignite by apache.
the class GridTcpCommunicationSpiLanTest method beforeTestsStarted.
/**
* {@inheritDoc}
*/
@Override
protected void beforeTestsStarted() throws Exception {
spi = createSpi();
spiRsrc = new IgniteTestResources(getMBeanServer());
locNode = new GridTestNode(spiRsrc.getNodeId());
GridSpiTestContext ctx = initSpiContext();
ctx.setLocalNode(locNode);
info(">>> Initialized context: nodeId=" + ctx.localNode().id());
spiRsrc.inject(spi);
lsnr = new MessageListener(spiRsrc.getNodeId());
spi.setListener(lsnr);
Map<String, Object> attrs = spi.getNodeAttributes();
locNode.setAttributes(attrs);
spi.spiStart(getTestIgniteInstanceName());
spi.onContextInitialized(ctx);
IgniteTestResources remoteRsrc = new IgniteTestResources();
remoteNode = new GridTestNode(remoteRsrc.getNodeId());
remoteNode.setAttributes(attrs);
remoteNode.setAttribute(U.spiAttribute(spi, TcpCommunicationSpi.ATTR_ADDRS), Collections.singleton(remoteAddr));
ctx.remoteNodes().add(remoteNode);
}
use of org.apache.ignite.testframework.junits.IgniteTestResources 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<>();
timeoutProcessor = new GridTimeoutProcessor(new GridTestKernalContext(log));
timeoutProcessor.start();
timeoutProcessor.onKernalStart(true);
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();
MessageFactoryProvider testMsgFactory = new MessageFactoryProvider() {
@Override
public void registerAll(IgniteMessageFactory factory) {
factory.register(GridTestMessage.DIRECT_TYPE, GridTestMessage::new);
}
};
ctx.messageFactory(new IgniteMessageFactoryImpl(new MessageFactory[] { new GridIoMessageFactory(), testMsgFactory }));
ctx.setLocalNode(node);
ctx.timeoutProcessor(timeoutProcessor);
spiRsrcs.add(rsrcs);
rsrcs.inject(spi);
spi.setListener(new TestListener());
node.order(i);
nodes.add(node);
spi.spiStart(getTestIgniteInstanceName() + (i + 1));
node.setAttributes(spi.getNodeAttributes());
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);
}
}
}
Aggregations