use of org.apache.ignite.testframework.junits.IgniteTestResources 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<>();
timeoutProcessor = new GridTimeoutProcessor(new GridTestKernalContext(log));
timeoutProcessor.start();
timeoutProcessor.onKernalStart(true);
for (int i = 0; i < SPI_CNT; i++) {
TcpCommunicationSpi spi = getSpi(i);
IgniteTestResources rsrcs = new IgniteTestResources();
GridTestNode node = new GridTestNode(rsrcs.getNodeId());
node.order(i);
GridSpiTestContext ctx = initSpiContext();
ctx.setLocalNode(node);
ctx.timeoutProcessor(timeoutProcessor);
spiRsrcs.add(rsrcs);
rsrcs.inject(spi);
GridTestUtils.setFieldValue(spi, IgniteSpiAdapter.class, "igniteInstanceName", "grid-" + i);
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.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();
ctx.setLocalNode(node);
ctx.timeoutProcessor(timeoutProcessor);
spiRsrcs.add(rsrcs);
rsrcs.inject(spi);
spi.setListener(new TestListener());
node.setAttributes(spi.getNodeAttributes());
node.order(i);
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.junits.IgniteTestResources in project ignite by apache.
the class AbstractDiscoverySelfTest method beforeTestsStarted.
/**
* {@inheritDoc}
*/
@Override
protected void beforeTestsStarted() throws Exception {
try {
for (int i = 0; i < getSpiCount(); i++) {
DiscoverySpi spi = getSpi(i);
IgniteTestResources rsrcMgr = new IgniteTestResources(getMBeanServer(i));
rsrcMgr.inject(spi);
spi.setNodeAttributes(Collections.<String, Object>singletonMap(TEST_ATTRIBUTE_NAME, "true"), fromString("99.99.99"));
spi.setListener(new DiscoverySpiListener() {
/**
* {@inheritDoc}
*/
@Override
public void onLocalNodeInitialized(ClusterNode locNode) {
// No-op.
}
@SuppressWarnings({ "NakedNotify" })
@Override
public void onDiscovery(int type, long topVer, ClusterNode node, Collection<ClusterNode> topSnapshot, Map<Long, Collection<ClusterNode>> topHist, @Nullable DiscoverySpiCustomMessage data) {
info("Discovery event [type=" + type + ", node=" + node + ']');
synchronized (mux) {
mux.notifyAll();
}
}
});
spi.setDataExchange(new DiscoverySpiDataExchange() {
@Override
public DiscoveryDataBag collect(DiscoveryDataBag dataBag) {
return dataBag;
}
@Override
public void onExchange(DiscoveryDataBag dataBag) {
// No-op.
}
});
GridSpiTestContext ctx = initSpiContext();
GridTestUtils.setFieldValue(spi, IgniteSpiAdapter.class, "spiCtx", ctx);
if (useSsl) {
IgniteMock ignite = GridTestUtils.getFieldValue(spi, IgniteSpiAdapter.class, "ignite");
IgniteConfiguration cfg = ignite.configuration().setSslContextFactory(GridTestUtils.sslFactory());
ignite.setStaticCfg(cfg);
}
spi.spiStart(getTestIgniteInstanceName() + i);
spis.add(spi);
spiRsrcs.add(rsrcMgr);
// Force to use test context instead of default dummy context.
spi.onContextInitialized(ctx);
}
} catch (Throwable e) {
e.printStackTrace();
}
spiStartTime = System.currentTimeMillis();
}
use of org.apache.ignite.testframework.junits.IgniteTestResources in project ignite by apache.
the class AbstractDiscoverySelfTest method afterTestsStopped.
/**
* {@inheritDoc}
*/
@Override
protected void afterTestsStopped() throws Exception {
assert spis.size() > 1;
assert spis.size() == spiRsrcs.size();
for (DiscoverySpi spi : spis) {
spi.setListener(null);
spi.spiStop();
}
for (IgniteTestResources rscrs : spiRsrcs) {
MBeanServer mBeanSrv = rscrs.getMBeanServer();
mBeanSrv.unregisterMBean(new ObjectName(HTTP_ADAPTOR_MBEAN_NAME));
rscrs.stopThreads();
}
for (HttpAdaptor adaptor : httpAdaptors) adaptor.stop();
// Clear.
spis.clear();
spiRsrcs.clear();
httpAdaptors.clear();
spiStartTime = 0;
tearDown();
}
use of org.apache.ignite.testframework.junits.IgniteTestResources in project ignite by apache.
the class IpcSharedMemoryBenchmarkReader method main.
/**
* @param args Args.
* @throws IgniteCheckedException If failed.
*/
public static void main(String[] args) throws IgniteCheckedException {
IpcSharedMemoryNativeLoader.load(null);
int nThreads = (args.length > 0 ? Integer.parseInt(args[0]) : 1);
final AtomicLong transferCntr = new AtomicLong();
Thread collector = new Thread(new Runnable() {
@SuppressWarnings("BusyWait")
@Override
public void run() {
try {
while (!done) {
Thread.sleep(5000);
X.println("Transfer rate: " + transferCntr.getAndSet(0) / (1024 * 1024 * 5) + " MB/sec");
}
} catch (InterruptedException ignored) {
// No-op.
}
}
});
collector.start();
Runtime.getRuntime().addShutdownHook(new Thread() {
@Override
public void run() {
System.out.println("Shutting down...");
done = true;
}
});
try (IpcSharedMemoryServerEndpoint srv = new IpcSharedMemoryServerEndpoint(U.defaultWorkDirectory())) {
new IgniteTestResources().inject(srv);
srv.start();
for (int i = 0; i < nThreads; i++) {
final IpcEndpoint endPnt = srv.accept();
new Thread(new Runnable() {
@Override
public void run() {
InputStream space = null;
try {
space = endPnt.inputStream();
byte[] buf = new byte[DST_BUFFER_SIZE];
int pos = 0;
while (!done) {
int maxRead = Math.min(buf.length - pos, DFLT_BUF_SIZE);
int read = space.read(buf, pos, maxRead);
if (read == -1) {
X.println("Space has been closed");
return;
}
transferCntr.addAndGet(read);
pos += read;
if (pos >= buf.length)
pos = 0;
}
} catch (Exception e) {
e.printStackTrace();
} finally {
U.closeQuiet(space);
}
}
}).start();
}
}
JOptionPane.showMessageDialog(null, "Press OK to stop READER.");
done = true;
}
Aggregations