Search in sources :

Example 21 with CI1

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();
        }
    }
}
Also used : GridJavaProcess(org.apache.ignite.internal.util.GridJavaProcess) Ignite(org.apache.ignite.Ignite) CI1(org.apache.ignite.internal.util.typedef.CI1) CountDownLatch(java.util.concurrent.CountDownLatch) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Example 22 with CI1

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;
}
Also used : IgniteFuture(org.apache.ignite.lang.IgniteFuture) ClusterGroup(org.apache.ignite.cluster.ClusterGroup) CI1(org.apache.ignite.internal.util.typedef.CI1) Nullable(org.jetbrains.annotations.Nullable)

Example 23 with CI1

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);
}
Also used : Input(com.esotericsoftware.kryo.io.Input) ObjectInput(java.io.ObjectInput) ByteArrayInputStream(java.io.ByteArrayInputStream) Output(com.esotericsoftware.kryo.io.Output) ObjectOutput(java.io.ObjectOutput) CI1(org.apache.ignite.internal.util.typedef.CI1) ByteArrayOutputStream(java.io.ByteArrayOutputStream) CO(org.apache.ignite.internal.util.typedef.CO) Kryo(com.esotericsoftware.kryo.Kryo) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Example 24 with CI1

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);
}
Also used : IgniteFuture(org.apache.ignite.lang.IgniteFuture) CI1(org.apache.ignite.internal.util.typedef.CI1) Semaphore(java.util.concurrent.Semaphore) Nullable(org.jetbrains.annotations.Nullable) IgniteInterruptedCheckedException(org.apache.ignite.internal.IgniteInterruptedCheckedException) IOException(java.io.IOException)

Example 25 with CI1

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();
}
Also used : AffinityTopologyVersion(org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion) IgniteCache(org.apache.ignite.IgniteCache) CI1(org.apache.ignite.internal.util.typedef.CI1) CountDownLatch(java.util.concurrent.CountDownLatch) IgniteInternalFuture(org.apache.ignite.internal.IgniteInternalFuture) Callable(java.util.concurrent.Callable) CyclicBarrier(java.util.concurrent.CyclicBarrier) AtomicLong(java.util.concurrent.atomic.AtomicLong) Transaction(org.apache.ignite.transactions.Transaction)

Aggregations

CI1 (org.apache.ignite.internal.util.typedef.CI1)32 IgniteInternalFuture (org.apache.ignite.internal.IgniteInternalFuture)12 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)11 ClusterNode (org.apache.ignite.cluster.ClusterNode)11 Test (org.junit.Test)11 IgniteFuture (org.apache.ignite.lang.IgniteFuture)9 ArrayList (java.util.ArrayList)8 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)8 IgniteException (org.apache.ignite.IgniteException)7 IgniteInterruptedCheckedException (org.apache.ignite.internal.IgniteInterruptedCheckedException)7 AffinityTopologyVersion (org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion)7 Collection (java.util.Collection)6 ClusterTopologyCheckedException (org.apache.ignite.internal.cluster.ClusterTopologyCheckedException)6 IgniteSpiException (org.apache.ignite.spi.IgniteSpiException)6 GridCommonAbstractTest (org.apache.ignite.testframework.junits.common.GridCommonAbstractTest)6 Nullable (org.jetbrains.annotations.Nullable)6 List (java.util.List)5 UUID (java.util.UUID)5 DiscoveryEvent (org.apache.ignite.events.DiscoveryEvent)5 GridFutureAdapter (org.apache.ignite.internal.util.future.GridFutureAdapter)5