use of org.apache.ignite.internal.util.typedef.CI1 in project ignite by apache.
the class IgniteNoClassOnServerAbstractTest method testNoClassOnServerNode.
/**
* @throws Exception If failed.
*/
@Test
public final void testNoClassOnServerNode() throws Exception {
info("Run test with client: " + clientClassName());
// Check class is really not available.
try {
Class.forName("org.apache.ignite.tests.p2p.cache.Person");
fail();
} catch (ClassNotFoundException ignore) {
// Expected exception.
}
try (Ignite ignite = Ignition.start(createConfiguration())) {
CacheConfiguration cfg = new CacheConfiguration(DEFAULT_CACHE_NAME);
// To store only value bytes.
cfg.setCopyOnRead(true);
ignite.createCache(cfg);
final CountDownLatch clientReadyLatch = new CountDownLatch(1);
Collection<String> jvmArgs = Arrays.asList("-ea", "-DIGNITE_QUIET=false");
GridJavaProcess clientNode = null;
try {
String cp = U.getIgniteHome() + "/modules/extdata/p2p/target/classes/";
clientNode = GridJavaProcess.exec(clientClassName(), null, log, new CI1<String>() {
@Override
public void apply(String s) {
info("Client node: " + s);
if (s.contains(NODE_START_MSG))
clientReadyLatch.countDown();
}
}, null, null, jvmArgs, cp);
assertTrue(clientReadyLatch.await(60, SECONDS));
int exitCode = clientNode.getProcess().waitFor();
assertEquals("Unexpected exit code", 0, exitCode);
} finally {
if (clientNode != null)
clientNode.killProcess();
}
}
}
use of org.apache.ignite.internal.util.typedef.CI1 in project ignite by apache.
the class GridJobExecutionLoadTestClientSemaphore method call.
/**
* {@inheritDoc}
*/
@Nullable
@Override
public Object call() throws Exception {
final IgniteInClosure<IgniteFuture<?>> lsnr = new CI1<IgniteFuture<?>>() {
@Override
public void apply(IgniteFuture<?> t) {
tasksSem.release();
}
};
ClusterGroup rmts = g.cluster().forRemotes();
while (!finish) {
tasksSem.acquire();
g.compute(rmts).executeAsync(GridJobExecutionLoadTestTask.class, null).listen(lsnr);
txCnt.increment();
}
return null;
}
use of org.apache.ignite.internal.util.typedef.CI1 in project ignite by apache.
the class GridMarshallerPerformanceTest method testKryo.
/**
* @throws Exception If failed.
*/
@Test
public void testKryo() throws Exception {
final Kryo kryo = new Kryo();
final ByteArrayOutputStream out = new ByteArrayOutputStream();
IgniteInClosure<TestObject> writer = new CI1<TestObject>() {
@Override
public void apply(TestObject obj) {
out.reset();
Output kryoOut = null;
try {
kryoOut = new Output(out);
kryo.writeObject(kryoOut, obj);
} finally {
U.close(kryoOut, log);
}
}
};
IgniteOutClosure<TestObject> reader = new CO<TestObject>() {
@Override
public TestObject apply() {
Input kryoIn = null;
try {
kryoIn = new Input(new ByteArrayInputStream(out.toByteArray()));
return kryo.readObject(kryoIn, TestObject.class);
} finally {
U.close(kryoIn, log);
}
}
};
runTest("Kryo", writer, reader);
}
use of org.apache.ignite.internal.util.typedef.CI1 in project ignite by apache.
the class GridJobExecutionSingleNodeSemaphoreLoadTest method runTest.
/**
* Runs the actual load test.
*
* @param g Grid.
* @param threadCnt Number of threads.
* @param taskCnt Number of tasks.
* @param dur Test duration.
* @param iterCntr Iteration counter.
*/
private static void runTest(final Ignite g, int threadCnt, int taskCnt, long dur, final LongAdder iterCntr) {
final Semaphore sem = new Semaphore(taskCnt);
final IgniteInClosure<IgniteFuture> lsnr = new CI1<IgniteFuture>() {
@Override
public void apply(IgniteFuture t) {
sem.release();
}
};
GridLoadTestUtils.runMultithreadedInLoop(new Callable<Object>() {
@Nullable
@Override
public Object call() throws Exception {
sem.acquire();
g.compute().executeAsync(GridJobExecutionLoadTestTask.class, null).listen(lsnr);
iterCntr.increment();
return null;
}
}, threadCnt, dur > 0 ? dur : Long.MAX_VALUE);
}
use of org.apache.ignite.internal.util.typedef.CI1 in project ignite by apache.
the class GridCacheFinishPartitionsSelfTest method runTransactions.
/**
* @param key Key.
* @param keyPart Key partition.
* @param waitParts Partitions to wait.
* @return Wait time.
* @throws Exception If failed.
*/
private long runTransactions(final String key, final int keyPart, final Collection<Integer> waitParts) throws Exception {
int threadNum = 1;
final CyclicBarrier barrier = new CyclicBarrier(threadNum);
final CountDownLatch latch = new CountDownLatch(threadNum);
final AtomicLong start = new AtomicLong();
GridTestUtils.runMultiThreaded(new Callable() {
@Override
public Object call() throws Exception {
if (barrier.await() == 0)
start.set(System.currentTimeMillis());
IgniteCache<String, String> cache = grid(0).cache(DEFAULT_CACHE_NAME);
Transaction tx = grid(0).transactions().txStart(PESSIMISTIC, REPEATABLE_READ);
cache.get(key);
IgniteInternalFuture<?> fut = grid.context().cache().context().partitionReleaseFuture(new AffinityTopologyVersion(GRID_CNT + 1));
fut.listen(new CI1<IgniteInternalFuture<?>>() {
@Override
public void apply(IgniteInternalFuture<?> e) {
latch.countDown();
}
});
assert !fut.isDone() : "Failed waiting for locks " + "[keyPart=" + keyPart + ", waitParts=" + waitParts + ", done=" + fut.isDone() + ']';
tx.commit();
return null;
}
}, threadNum, "test-finish-partitions-thread");
latch.await();
return System.currentTimeMillis() - start.get();
}
Aggregations