Java Code Examples for org.apache.ignite.Ignite#atomicSequence()
The following examples show how to use
org.apache.ignite.Ignite#atomicSequence() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: GridCacheMultiNodeDataStructureTest.java From ignite with Apache License 2.0 | 6 votes |
/** * * @param g Grid. * @param cacheName Cache name. */ private static void sample(Ignite g, String cacheName) { IgniteAtomicLong atomicLong = g.atomicLong("keygen", 0, true); IgniteAtomicSequence seq = g.atomicSequence("keygen", 0, true); seq.incrementAndGet(); seq.incrementAndGet(); seq.incrementAndGet(); seq.incrementAndGet(); atomicLong.incrementAndGet(); atomicLong.incrementAndGet(); atomicLong.incrementAndGet(); X.println(cacheName + ": Seq: " + seq.get() + " atomicLong " + atomicLong.get()); }
Example 2
Source File: GridCacheDataStructuresLoadTest.java From ignite with Apache License 2.0 | 5 votes |
@Override public void applyx(Ignite ignite) { IgniteAtomicSequence as = ignite.atomicSequence(TEST_SEQ_NAME, 0, true); for (int i = 0; i < operationsPerTx; i++) { as.addAndGet(RAND.nextInt(MAX_INT) + 1); long cnt = writes.incrementAndGet(); if (cnt % WRITE_LOG_MOD == 0) info("Performed " + cnt + " writes."); } }
Example 3
Source File: GridCacheDataStructuresLoadTest.java From ignite with Apache License 2.0 | 5 votes |
@Override public void applyx(Ignite ignite) { IgniteAtomicSequence as = ignite.atomicSequence(TEST_SEQ_NAME, 0, true); for (int i = 0; i < operationsPerTx; i++) { as.get(); long cnt = reads.incrementAndGet(); if (cnt % READ_LOG_MOD == 0) info("Performed " + cnt + " reads."); } }
Example 4
Source File: GridCacheSequenceApiSelfAbstractTest.java From ignite with Apache License 2.0 | 5 votes |
/** * Tests that basic API works correctly when there are multiple structures in multiple groups. * * @throws Exception If failed. */ @Test public void testMultipleStructuresInDifferentGroups() throws Exception { Ignite ignite = grid(0); AtomicConfiguration cfg = new AtomicConfiguration().setGroupName("grp1"); IgniteAtomicSequence seq1 = ignite.atomicSequence("seq1", 1, true); IgniteAtomicSequence seq2 = ignite.atomicSequence("seq2", 2, true); IgniteAtomicSequence seq3 = ignite.atomicSequence("seq3", cfg, 3, true); IgniteAtomicSequence seq4 = ignite.atomicSequence("seq4", cfg, 4, true); assertNull(ignite.atomicSequence("seq1", cfg, 1, false)); assertNull(ignite.atomicSequence("seq2", cfg, 1, false)); assertNull(ignite.atomicSequence("seq3", 1, false)); assertNull(ignite.atomicSequence("seq4", 1, false)); assertEquals(11, seq1.addAndGet(10)); assertEquals(12, seq2.addAndGet(10)); assertEquals(13, seq3.addAndGet(10)); assertEquals(14, seq4.addAndGet(10)); seq2.close(); seq4.close(); assertTrue(seq2.removed()); assertTrue(seq4.removed()); assertNull(ignite.atomicSequence("seq2", 2, false)); assertNull(ignite.atomicSequence("seq4", cfg, 4, false)); assertFalse(seq1.removed()); assertFalse(seq3.removed()); assertNotNull(ignite.atomicSequence("seq1", 1, false)); assertNotNull(ignite.atomicSequence("seq3", cfg, 3, false)); }
Example 5
Source File: GridCacheSequenceApiSelfAbstractTest.java From ignite with Apache License 2.0 | 5 votes |
/** * Tests that reserveSize value from explicit configuration takes preference. * * @throws Exception If failed. */ @Test public void testSequenceReserveSizeFromExplicitConfiguration() throws Exception { Ignite ignite = grid(0); IgniteAtomicSequence seq = ignite.atomicSequence("seq", new AtomicConfiguration().setAtomicSequenceReserveSize(BATCH_SIZE + 1), 0, true); assertEquals(BATCH_SIZE + 1, seq.batchSize()); }
Example 6
Source File: AtomicCacheAffinityConfigurationTest.java From ignite with Apache License 2.0 | 5 votes |
/** * */ private void checkAtomics() { Ignite node0 = grid(0); node0.atomicLong("l1", 0, true).incrementAndGet(); node0.atomicSequence("s1", 10, true); for (int i = 0; i < 3; i++) { assertEquals(1, ignite(i).atomicLong("l1", 0, false).get()); assertNotNull(ignite(i).atomicSequence("s1", 0, false)); ignite(i).atomicSequence("s1", 0, false).getAndIncrement(); } }
Example 7
Source File: IgniteChangeGlobalStateDataStructureTest.java From ignite with Apache License 2.0 | 4 votes |
/** * */ @Test public void testDeActivateAndActivateAtomicSequence() { String seqName = "mySeq"; Ignite ig1 = primary(0); Ignite ig2 = primary(1); Ignite ig3 = primary(2); IgniteAtomicSequence seqExp1 = ig1.atomicSequence(seqName, 0, true); IgniteAtomicSequence seqExp2 = ig2.atomicSequence(seqName, 0, false); IgniteAtomicSequence seqExp3 = ig3.atomicSequence(seqName, 0, false); assertEquals(0, seqExp1.get()); assertEquals(1000, seqExp2.get()); assertEquals(2000, seqExp3.get()); seqExp1.incrementAndGet(); seqExp2.incrementAndGet(); seqExp3.incrementAndGet(); assertTrue(ig1.active()); assertTrue(ig2.active()); assertTrue(ig3.active()); ig2.active(false); IgniteEx ex1 = (IgniteEx)ig1; IgniteEx ex2 = (IgniteEx)ig2; IgniteEx ex3 = (IgniteEx)ig3; GridCacheProcessor cache1 = ex1.context().cache(); GridCacheProcessor cache2 = ex2.context().cache(); GridCacheProcessor cache3 = ex3.context().cache(); assertTrue(F.isEmpty(cache1.jcaches())); assertTrue(F.isEmpty(cache2.jcaches())); assertTrue(F.isEmpty(cache3.jcaches())); assertTrue(!ig1.active()); assertTrue(!ig2.active()); assertTrue(!ig3.active()); ig3.active(true); assertTrue(ig1.active()); assertTrue(ig2.active()); assertTrue(ig3.active()); IgniteAtomicSequence seqAct1 = ig1.atomicSequence(seqName, 0, false); IgniteAtomicSequence seqAct2 = ig2.atomicSequence(seqName, 0, false); IgniteAtomicSequence seqAct3 = ig3.atomicSequence(seqName, 0, false); assertEquals(1, seqAct1.get()); assertEquals(1001, seqAct2.get()); assertEquals(2001, seqAct3.get()); seqAct1.incrementAndGet(); assertEquals(2, seqAct1.get()); assertEquals(1001, seqAct2.get()); assertEquals(2001, seqAct3.get()); seqAct2.incrementAndGet(); assertEquals(2, seqAct1.get()); assertEquals(1002, seqAct2.get()); assertEquals(2001, seqAct3.get()); seqAct3.incrementAndGet(); assertEquals(2, seqAct1.get()); assertEquals(1002, seqAct2.get()); assertEquals(2002, seqAct3.get()); }
Example 8
Source File: IgniteClientReconnectAtomicsTest.java From ignite with Apache License 2.0 | 4 votes |
/** * @throws Exception If failed. */ @Test public void testAtomicsReconnectClusterRestart() throws Exception { Ignite client = grid(serverCount()); assertTrue(client.cluster().localNode().isClient()); final IgniteAtomicLong atomicLong = client.atomicLong("atomicLong", 1L, true); final IgniteAtomicReference<Integer> atomicRef = client.atomicReference("atomicRef", 1, true); final IgniteAtomicStamped<Integer, Integer> atomicStamped = client.atomicStamped("atomicStamped", 1, 1, true); final IgniteCountDownLatch latch = client.countDownLatch("latch", 1, true, true); final IgniteAtomicSequence seq = client.atomicSequence("seq", 1L, true); Ignite srv = grid(0); reconnectServersRestart(log, client, Collections.singleton(srv), new Callable<Collection<Ignite>>() { @Override public Collection<Ignite> call() throws Exception { return Collections.singleton((Ignite)startGrid(0)); } }); GridTestUtils.assertThrows(log, new Callable<Void>() { @Override public Void call() throws Exception { atomicStamped.compareAndSet(1, 1, 2, 2); return null; } }, IllegalStateException.class, null); GridTestUtils.assertThrows(log, new Callable<Void>() { @Override public Void call() throws Exception { atomicRef.compareAndSet(1, 2); return null; } }, IllegalStateException.class, null); GridTestUtils.assertThrows(log, new Callable<Void>() { @Override public Void call() throws Exception { atomicLong.incrementAndGet(); return null; } }, IllegalStateException.class, null); GridTestUtils.assertThrows(log, new Callable<Void>() { @Override public Void call() throws Exception { seq.getAndAdd(1L); return null; } }, IllegalStateException.class, null); }
Example 9
Source File: GridCommandHandlerTest.java From ignite with Apache License 2.0 | 4 votes |
/** */ @Test public void testCacheSequence() throws Exception { Ignite ignite = startGrid(); ignite.cluster().active(true); Ignite client = startGrid("client"); final IgniteAtomicSequence seq1 = client.atomicSequence("testSeq", 1, true); seq1.get(); final IgniteAtomicSequence seq2 = client.atomicSequence("testSeq2", 10, true); seq2.get(); injectTestSystemOut(); assertEquals(EXIT_CODE_OK, execute("--cache", "list", "testSeq.*", "--seq")); String out = testOut.toString(); assertContains(log, out, "testSeq"); assertContains(log, out, "testSeq2"); }
Example 10
Source File: JmhSequenceBenchmark.java From ignite with Apache License 2.0 | 3 votes |
/** * Setup. */ @Setup public void setup() { Ignite node = Ignition.start(configuration("NODE_0")); int nodes = intProperty(PROP_DATA_NODES, 4); for (int i = 1; i < nodes; i++) Ignition.start(configuration("NODE_" + i)); boolean isClient = booleanProperty(PROP_CLIENT_MODE); if (isClient) { IgniteConfiguration clientCfg = configuration("client"); clientCfg.setClientMode(true); node = Ignition.start(clientCfg); } AtomicConfiguration acfg = new AtomicConfiguration(); int batchSize = intProperty(PROP_BATCH_SIZE); randomBound = batchSize < 10 ? 1 : batchSize / 10; acfg.setAtomicSequenceReserveSize(batchSize); seq = node.atomicSequence("seq", acfg, 0, true); }
Example 11
Source File: IgnitePersistentStoreDataStructuresTest.java From ignite with Apache License 2.0 | 3 votes |
/** * @throws Exception If failed. */ @Test public void testSequence() throws Exception { Ignite ignite = startGrids(4); ignite.active(true); IgniteAtomicSequence sequence = ignite.atomicSequence("testSequence", 0, true); int i = 0; while (i < 1000) { sequence.incrementAndGet(); i++; } stopAllGrids(); ignite = startGrids(4); ignite.active(true); sequence = ignite.atomicSequence("testSequence", 0, false); assertTrue(sequence.incrementAndGet() > i); }
Example 12
Source File: IgniteSequenceInternalCleanupTest.java From ignite with Apache License 2.0 | 3 votes |
/** */ @Test public void testDeactivate() throws Exception { try { Ignite ignite = startGridsMultiThreaded(GRIDS_CNT); ignite.cache("test0").put(0, 0); int id = 0; for (Ignite ig : G.allGrids()) { IgniteAtomicSequence seq = ig.atomicSequence("testSeq", 0, true); long id0 = seq.getAndIncrement(); assertEquals(id0, id); id += SEQ_RESERVE; } doSleep(1000); long puts = ignite.cache("test0").metrics().getCachePuts(); assertEquals(1, puts); grid(GRIDS_CNT - 1).cluster().active(false); ignite.cluster().active(true); doSleep(500); long putsAfter = ignite.cache("test0").metrics().getCachePuts(); assertEquals(1, putsAfter); } finally { stopAllGrids(); } }
Example 13
Source File: IgniteClientReconnectAtomicsTest.java From ignite with Apache License 2.0 | 3 votes |
/** * @throws Exception If failed. */ @Test public void testAtomicSeqReconnect() throws Exception { Ignite client = grid(serverCount()); assertTrue(client.cluster().localNode().isClient()); Ignite srv = ignite(0); IgniteAtomicSequence clientAtomicSeq = client.atomicSequence("atomicSeq", 0, true); assertEquals(1L, clientAtomicSeq.incrementAndGet()); final IgniteAtomicSequence srvAtomicSeq = srv.atomicSequence("atomicSeq", 0, false); assertEquals(1001L, srvAtomicSeq.incrementAndGet()); reconnectClientNode(client, srv, new Runnable() { @Override public void run() { assertEquals(1002L, srvAtomicSeq.incrementAndGet()); } }); assertEquals(2L, clientAtomicSeq.incrementAndGet()); assertEquals(1003L, srvAtomicSeq.incrementAndGet()); assertEquals(3L, clientAtomicSeq.incrementAndGet()); clientAtomicSeq.close(); }