Here are the examples of the java api class org.apache.ignite.Ignite taken from open source projects.
1. IgniteDynamicClientCacheStartSelfTest#testCreateCloseClientCache1()
Project: ignite
File: IgniteDynamicClientCacheStartSelfTest.java
File: IgniteDynamicClientCacheStartSelfTest.java
/** * @throws Exception If failed. */ public void testCreateCloseClientCache1() throws Exception { Ignite ignite0 = startGrid(0); client = true; Ignite clientNode = startGrid(1); client = false; ignite0.createCache(new CacheConfiguration<>()); clientNode.cache(null); clientNode.cache(null).close(); clientNode.cache(null); startGrid(2); checkCache(clientNode, null, false, false); }
2. IgniteInternalCacheTypesTest#testCacheTypes()
Project: ignite
File: IgniteInternalCacheTypesTest.java
File: IgniteInternalCacheTypesTest.java
/** * @throws Exception If failed. */ public void testCacheTypes() throws Exception { Ignite ignite0 = startGrid(0); checkCacheTypes(ignite0, CACHE1); Ignite ignite1 = startGrid(1); checkCacheTypes(ignite1, CACHE1); CacheConfiguration ccfg = defaultCacheConfiguration(); ccfg.setName(CACHE2); assertNotNull(ignite0.createCache(ccfg)); checkCacheTypes(ignite0, CACHE1, CACHE2); checkCacheTypes(ignite1, CACHE1, CACHE2); Ignite ignite2 = startGrid(2); checkCacheTypes(ignite0, CACHE1, CACHE2); checkCacheTypes(ignite1, CACHE1, CACHE2); checkCacheTypes(ignite2, CACHE1, CACHE2); }
3. NearCachePutAllMultinodeTest#beforeTest()
Project: ignite
File: NearCachePutAllMultinodeTest.java
File: NearCachePutAllMultinodeTest.java
@Override protected void beforeTest() throws Exception { startGridsMultiThreaded(GRID_CNT - 2); client = true; Ignite grid = startGrid(GRID_CNT - 2); grid.createNearCache(null, new NearCacheConfiguration()); grid = startGrid(GRID_CNT - 1); grid.cache(null); }
4. ComputeJobCancelWithServiceSelfTest#testJobCancel()
Project: ignite
File: ComputeJobCancelWithServiceSelfTest.java
File: ComputeJobCancelWithServiceSelfTest.java
/** * @throws Exception If failed. */ public void testJobCancel() throws Exception { Ignite server = startGrid("server"); server.services().deployNodeSingleton("my-service", new MyService()); Ignition.setClientMode(true); Ignite client = startGrid("client"); IgniteCompute compute = client.compute().withAsync(); compute.execute(new MyTask(), null); ComputeTaskFuture<Integer> fut = compute.future(); Thread.sleep(3000); server.close(); assertEquals(42, fut.get().intValue()); }
5. GridCacheJdbcBlobStoreMultithreadedSelfTest#beforeTest()
Project: ignite
File: GridCacheJdbcBlobStoreMultithreadedSelfTest.java
File: GridCacheJdbcBlobStoreMultithreadedSelfTest.java
/** {@inheritDoc} */ @Override protected void beforeTest() throws Exception { startGridsMultiThreaded(GRID_CNT - 2); client = true; Ignite grid = startGrid(GRID_CNT - 2); grid.createNearCache(null, new NearCacheConfiguration()); grid = startGrid(GRID_CNT - 1); grid.cache(null); }
6. GridCacheNearReaderPreloadSelfTest#startUp()
Project: ignite
File: GridCacheNearReaderPreloadSelfTest.java
File: GridCacheNearReaderPreloadSelfTest.java
/** * Startup routine. * * @throws Exception If failed. */ private void startUp() throws Exception { TcpDiscoveryIpFinder ipFinder = new TcpDiscoveryVmIpFinder(true); Ignite node1 = G.start(dataNode(ipFinder, "node1")); Ignite node2 = G.start(dataNode(ipFinder, "node2")); Ignite node3 = G.start(dataNode(ipFinder, "node3")); info("Node 1: " + node1.cluster().localNode().id()); info("Node 2: " + node2.cluster().localNode().id()); info("Node 3: " + node3.cluster().localNode().id()); cache1 = node1.cache(CACHE_NAME); cache2 = node2.cache(CACHE_NAME); cache3 = node3.cache(CACHE_NAME); }
7. GridCacheColocatedDebugTest#checkStoreWithValues()
Project: ignite
File: GridCacheColocatedDebugTest.java
File: GridCacheColocatedDebugTest.java
/** * @param map Values to check. * @throws Exception If failed. */ private void checkStoreWithValues(Map<Integer, String> map) throws Exception { Ignite g0 = grid(0); Ignite g1 = grid(1); Ignite g2 = grid(2); g0.cache(null).putAll(map); checkStore(g0, map); checkStore(g1, Collections.<Integer, String>emptyMap()); checkStore(g2, Collections.<Integer, String>emptyMap()); clearStores(3); try (Transaction tx = g0.transactions().txStart(OPTIMISTIC, READ_COMMITTED)) { g0.cache(null).putAll(map); tx.commit(); checkStore(g0, map); checkStore(g1, Collections.<Integer, String>emptyMap()); checkStore(g2, Collections.<Integer, String>emptyMap()); clearStores(3); } }
8. CacheLateAffinityAssignmentTest#testCreateCloseClientCacheOnCoordinator1()
Project: ignite
File: CacheLateAffinityAssignmentTest.java
File: CacheLateAffinityAssignmentTest.java
/** * @throws Exception If failed. */ public void testCreateCloseClientCacheOnCoordinator1() throws Exception { cacheC = new IgniteClosure<String, CacheConfiguration[]>() { @Override public CacheConfiguration[] apply(String gridName) { return null; } }; cacheNodeFilter = new CacheNodeFilter(F.asList(getTestGridName(0))); Ignite ignite0 = startServer(0, 1); ignite0.createCache(cacheConfiguration()); ignite0.cache(CACHE_NAME1); ignite0.cache(CACHE_NAME1).close(); startServer(1, 2); startServer(2, 3); }
9. TcpClientDiscoverySpiSelfTest#testPingFailedClientNode()
Project: ignite
File: TcpClientDiscoverySpiSelfTest.java
File: TcpClientDiscoverySpiSelfTest.java
/** * @throws Exception If failed. */ public void testPingFailedClientNode() throws Exception { startServerNodes(2); startClientNodes(1); checkNodes(2, 1); Ignite srv0 = G.ignite("server-0"); Ignite srv1 = G.ignite("server-1"); Ignite client = G.ignite("client-0"); if (!useFailureDetectionTimeout()) ((TcpDiscoverySpi) srv0.configuration().getDiscoverySpi()).setAckTimeout(1000); ((TestTcpDiscoverySpi) client.configuration().getDiscoverySpi()).pauseSocketWrite(); assert !((IgniteEx) srv1).context().discovery().pingNode(client.cluster().localNode().id()); assert !((IgniteEx) srv0).context().discovery().pingNode(client.cluster().localNode().id()); ((TestTcpDiscoverySpi) client.configuration().getDiscoverySpi()).resumeAll(); assert ((IgniteEx) srv1).context().discovery().pingNode(client.cluster().localNode().id()); assert ((IgniteEx) srv0).context().discovery().pingNode(client.cluster().localNode().id()); }
10. TcpClientDiscoverySpiSelfTest#testPing()
Project: ignite
File: TcpClientDiscoverySpiSelfTest.java
File: TcpClientDiscoverySpiSelfTest.java
/** * @throws Exception If failed. */ public void testPing() throws Exception { startServerNodes(2); startClientNodes(1); Ignite srv0 = G.ignite("server-0"); Ignite srv1 = G.ignite("server-1"); Ignite client = G.ignite("client-0"); assert ((IgniteEx) srv0).context().discovery().pingNode(client.cluster().localNode().id()); assert ((IgniteEx) srv1).context().discovery().pingNode(client.cluster().localNode().id()); assert ((IgniteEx) client).context().discovery().pingNode(srv0.cluster().localNode().id()); assert ((IgniteEx) client).context().discovery().pingNode(srv1.cluster().localNode().id()); }
11. GridCacheNearTxForceKeyTest#testNearTx()
Project: ignite
File: GridCacheNearTxForceKeyTest.java
File: GridCacheNearTxForceKeyTest.java
/** * Test provokes scenario when primary node sends force key request to node started transaction. * * @throws Exception If failed. */ public void testNearTx() throws Exception { Ignite ignite0 = startGrid(0); IgniteCache<Integer, Integer> cache = ignite0.cache(null); Ignite ignite1 = startGrid(1); // This key should become primary for ignite1. final Integer key = ignite0.configuration().getMarshaller() instanceof OptimizedMarshaller ? 2 : 7; assertNull(cache.getAndPut(key, key)); awaitPartitionMapExchange(); assertTrue(ignite0.affinity(null).isPrimary(ignite1.cluster().localNode(), key)); }
12. GridCacheNearMultiNodeSelfTest#testReadThroughAndPut()
Project: ignite
File: GridCacheNearMultiNodeSelfTest.java
File: GridCacheNearMultiNodeSelfTest.java
/** @throws Exception If failed. */ public void testReadThroughAndPut() throws Exception { Integer key = 100000; Ignite primary; Ignite backup; if (grid(0) == primaryGrid(key)) { primary = grid(0); backup = grid(1); } else { primary = grid(1); backup = grid(0); } assertEquals(String.valueOf(key), backup.cache(null).get(key)); primary.cache(null).put(key, "a"); assertEquals("a", backup.cache(null).get(key)); }
13. GridCachePreloadEventsAbstractSelfTest#testPreloadEvents()
Project: ignite
File: GridCachePreloadEventsAbstractSelfTest.java
File: GridCachePreloadEventsAbstractSelfTest.java
/** * @throws Exception if failed. */ public void testPreloadEvents() throws Exception { Ignite g1 = startGrid("g1"); IgniteCache<Integer, String> cache = g1.cache(null); cache.put(1, "val1"); cache.put(2, "val2"); cache.put(3, "val3"); Ignite g2 = startGrid("g2"); Collection<Event> evts = g2.events().localQuery(F.<Event>alwaysTrue(), EVT_CACHE_REBALANCE_OBJECT_LOADED); checkPreloadEvents(evts, g2, U.toIntList(new int[] { 1, 2, 3 })); }
14. CacheLateAffinityAssignmentTest#testDelayAssignmentCoordinatorLeave2()
Project: ignite
File: CacheLateAffinityAssignmentTest.java
File: CacheLateAffinityAssignmentTest.java
/** * Wait for rebalance, coordinator leaves, 3 nodes. * * @throws Exception If failed. */ public void testDelayAssignmentCoordinatorLeave2() throws Exception { Ignite ignite0 = startServer(0, 1); Ignite ignite1 = startServer(1, 2); checkAffinity(2, topVer(2, 1), true); TestRecordingCommunicationSpi spi0 = (TestRecordingCommunicationSpi) ignite0.configuration().getCommunicationSpi(); TestRecordingCommunicationSpi spi1 = (TestRecordingCommunicationSpi) ignite1.configuration().getCommunicationSpi(); blockSupplySend(spi0, CACHE_NAME1); blockSupplySend(spi1, CACHE_NAME1); startServer(2, 3); stopNode(0, 4); checkAffinity(2, topVer(4, 0), false); spi1.stopBlock(); checkAffinity(2, topVer(4, 1), true); }
15. GridAffinitySelfTest#testAffinity()
Project: ignite
File: GridAffinitySelfTest.java
File: GridAffinitySelfTest.java
/** * @throws IgniteCheckedException If failed. */ public void testAffinity() throws Exception { Ignite g1 = grid(1); Ignite g2 = grid(2); assert caches(g1).size() == 0; assert F.first(caches(g2)).getCacheMode() == PARTITIONED; awaitPartitionMapExchange(); Map<ClusterNode, Collection<String>> map = g1.<String>affinity(null).mapKeysToNodes(F.asList("1")); assertNotNull(map); assertEquals("Invalid map size: " + map.size(), 1, map.size()); assertEquals(F.first(map.keySet()), g2.cluster().localNode()); UUID id1 = g1.affinity(null).mapKeyToNode("2").id(); assertNotNull(id1); assertEquals(g2.cluster().localNode().id(), id1); UUID id2 = g1.affinity(null).mapKeyToNode("3").id(); assertNotNull(id2); assertEquals(g2.cluster().localNode().id(), id2); }
16. ClusterNodeMetricsSelfTest#testClusterNodeMetrics()
Project: ignite
File: ClusterNodeMetricsSelfTest.java
File: ClusterNodeMetricsSelfTest.java
/** * @throws Exception If failed. */ public void testClusterNodeMetrics() throws Exception { final Ignite ignite0 = grid(); final Ignite ignite1 = startGrid(1); GridTestUtils.waitForCondition(new GridAbsPredicate() { @Override public boolean apply() { return ignite0.cluster().nodes().size() == 2 && ignite1.cluster().nodes().size() == 2; } }, 3000L); ClusterMetrics metrics0 = ignite0.cluster().localNode().metrics(); ClusterMetrics nodesMetrics = ignite0.cluster().forNode(ignite0.cluster().localNode(), ignite1.cluster().localNode()).metrics(); assertEquals(metrics0.getTotalCpus(), nodesMetrics.getTotalCpus()); assertEquals(1, metrics0.getTotalNodes()); assertEquals(2, nodesMetrics.getTotalNodes()); assert metrics0.getHeapMemoryUsed() > 0; assert metrics0.getHeapMemoryTotal() > 0; }
17. IgniteCountDownLatchAbstractSelfTest#testLatchBroadcast()
Project: ignite
File: IgniteCountDownLatchAbstractSelfTest.java
File: IgniteCountDownLatchAbstractSelfTest.java
/** * @throws Exception If failed. */ public void testLatchBroadcast() throws Exception { Ignite ignite = grid(0); ClusterGroup srvsGrp = ignite.cluster().forServers(); int numOfSrvs = srvsGrp.nodes().size(); ignite.destroyCache("testCache"); IgniteCache<Object, Object> cache = ignite.createCache("testCache"); for (ClusterNode node : srvsGrp.nodes()) cache.put(String.valueOf(node.id()), 0); for (int i = 0; i < 500; i++) { IgniteCountDownLatch latch1 = createLatch1(ignite, numOfSrvs); IgniteCountDownLatch latch2 = createLatch2(ignite, numOfSrvs); ignite.compute(srvsGrp).broadcast(new IgniteRunnableJob(latch1, latch2, i)); assertTrue(latch2.await(10000)); } }
18. GridDiscoveryManagerAliveCacheSelfTest#stopTempNodes()
Project: ignite
File: GridDiscoveryManagerAliveCacheSelfTest.java
File: GridDiscoveryManagerAliveCacheSelfTest.java
/** * Stops temporary nodes. */ private void stopTempNodes() { Collection<Ignite> toRmv = new ArrayList<>(alive.subList(0, TMP_NODES_CNT)); alive.removeAll(toRmv); // Remove listeners to avoid receiving events from stopping nodes. for (Ignite g : toRmv) g.events().stopLocalListen(lsnr, EventType.EVT_NODE_LEFT, EventType.EVT_NODE_FAILED); for (Iterator<Ignite> itr = toRmv.iterator(); itr.hasNext(); ) { Ignite g = itr.next(); if (g.cluster().localNode().isClient()) { G.stop(g.name(), false); itr.remove(); } } for (Ignite g : toRmv) { assert !g.cluster().localNode().isClient(); G.stop(g.name(), false); } }
19. GridFactorySelfTest#testIgnitionStartDefault()
Project: ignite
File: GridFactorySelfTest.java
File: GridFactorySelfTest.java
/** * @throws Exception If failed. */ public void testIgnitionStartDefault() throws Exception { try (Ignite ignite = Ignition.start()) { log.info("Started1: " + ignite.name()); try { Ignition.start(); fail(); } catch (IgniteException expected) { } } try (Ignite ignite = Ignition.start()) { log.info("Started2: " + ignite.name()); } }
20. CacheQueryNewClientSelfTest#testQueryFromNewClientCustomSchemaName()
Project: ignite
File: CacheQueryNewClientSelfTest.java
File: CacheQueryNewClientSelfTest.java
/** * @throws Exception If failed. */ public void testQueryFromNewClientCustomSchemaName() throws Exception { Ignite srv = startGrid("server"); IgniteCache<Integer, Integer> cache1 = srv.createCache(new CacheConfiguration<Integer, Integer>().setName("cache1").setSqlSchema("cache1_sql").setIndexedTypes(Integer.class, Integer.class)); IgniteCache<Integer, Integer> cache2 = srv.createCache(new CacheConfiguration<Integer, Integer>().setName("cache2").setSqlSchema("cache2_sql").setIndexedTypes(Integer.class, Integer.class)); for (int i = 0; i < 10; i++) { cache1.put(i, i); cache2.put(i, i); } Ignition.setClientMode(true); Ignite client = startGrid("client"); IgniteCache<Integer, Integer> cache = client.cache("cache1"); List<List<?>> res = cache.query(new SqlFieldsQuery("select i1._val, i2._val from Integer i1 cross join cache2_sql.Integer i2")).getAll(); assertEquals(100, res.size()); }
21. HadoopIgfsDualAbstractSelfTest#beforeTestsStarted()
Project: ignite
File: HadoopIgfsDualAbstractSelfTest.java
File: HadoopIgfsDualAbstractSelfTest.java
/** {@inheritDoc} */ @Override protected void beforeTestsStarted() throws Exception { chunk = new byte[128]; for (int i = 0; i < chunk.length; i++) chunk[i] = (byte) i; Ignite igniteSecondary = startGridWithIgfs("grid-secondary", "igfs-secondary", PRIMARY, null, SECONDARY_REST_CFG); IgfsSecondaryFileSystem hadoopFs = new IgniteHadoopIgfsSecondaryFileSystem(SECONDARY_URI, SECONDARY_CFG); Ignite ignite = startGridWithIgfs("grid", "igfs", mode, hadoopFs, PRIMARY_REST_CFG); igfsSecondary = (IgfsImpl) igniteSecondary.fileSystem("igfs-secondary"); igfs = (IgfsImpl) ignite.fileSystem("igfs"); }
22. GridSwapSpaceSpiConsistencySelfTest#testClientNodeAnySwapSpaceSpi()
Project: ignite
File: GridSwapSpaceSpiConsistencySelfTest.java
File: GridSwapSpaceSpiConsistencySelfTest.java
/** * Client nodes should join to grid with any swap policy */ public void testClientNodeAnySwapSpaceSpi() throws Exception { startGrid(GRID_WITHOUT_SWAP_SPACE); Ignite client1 = startGrid(GRID_CLIENT_WITH_SWAP_SPACE); Ignite client2 = startGrid(GRID_CLIENT_WITHOUT_SWAP_SPACE); IgniteCache<Integer, String> cache1 = client1.createCache("TestCache"); cache1.put(1, "one"); IgniteCache<Integer, String> cache2 = client2.getOrCreateCache("TestCache"); assert cache2.get(1).equals("one"); }
23. GridTcpSpiForwardingSelfTest#testForward()
Project: ignite
File: GridTcpSpiForwardingSelfTest.java
File: GridTcpSpiForwardingSelfTest.java
/** * @throws Exception If any error occurs. */ @SuppressWarnings("UnusedDeclaration") public void testForward() throws Exception { InetAddress locHost = InetAddress.getByName("127.0.0.1"); try (GridTcpForwarder tcpForward1 = new GridTcpForwarder(locHost, extPort1, locHost, locPort1, log); GridTcpForwarder tcpForward2 = new GridTcpForwarder(locHost, extPort2, locHost, locPort2, log); GridTcpForwarder tcpForward3 = new GridTcpForwarder(locHost, commExtPort1, locHost, commLocPort1, log); GridTcpForwarder tcpForward4 = new GridTcpForwarder(locHost, commExtPort2, locHost, commLocPort2, log); Ignite g1 = startGrid(0); Ignite g2 = startGrid(1)) { assertEquals(2, grid(0).cluster().nodes().size()); assertEquals(2, grid(1).cluster().nodes().size()); Collection<Integer> t = g1.compute().broadcast(new IgniteCallable<Integer>() { @Override public Integer call() throws Exception { return 13; } }); assertEquals(F.asList(13, 13), t); } }
24. IgfsStartCacheTest#testCacheStart()
Project: ignite
File: IgfsStartCacheTest.java
File: IgfsStartCacheTest.java
/** * @throws Exception If failed. */ public void testCacheStart() throws Exception { Ignite g0 = G.start(config(true, 0)); checkIgfsCaches(g0); Ignite g1 = G.start(config(false, 1)); checkIgfsCaches(g1); IgniteFileSystem igfs = g0.fileSystem("igfs"); igfs.mkdirs(new IgfsPath("/test")); try (BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(igfs.create(new IgfsPath("/test/test.file"), true)))) { for (int i = 0; i < 1000; i++) bw.write("test-" + i); } }
25. IgniteCacheConfigurationTemplateTest#testStartClientNodeFirst()
Project: ignite
File: IgniteCacheConfigurationTemplateTest.java
File: IgniteCacheConfigurationTemplateTest.java
/** * @throws Exception If failed. */ public void testStartClientNodeFirst() throws Exception { addTemplate = true; clientMode = true; Ignite ignite0 = startGrid(0); checkNoTemplateCaches(0); addTemplate = false; clientMode = false; Ignite ignite1 = startGrid(1); checkGetOrCreate(ignite1, "org.apache.ignite.test.cache1", 4); checkGetOrCreate(ignite1, "org.apache.ignite.test.cache1", 4); checkGetOrCreate(ignite1, "org.apache.ignite1", 3); checkGetOrCreate(ignite1, "org.apache.ignite1", 3); checkGetOrCreate(ignite0, "org.apache.ignite1", 3); checkGetOrCreate(ignite0, "org.apache.ignite1", 3); }
26. IgniteCacheConfigurationDefaultTemplateTest#testDefaultTemplate()
Project: ignite
File: IgniteCacheConfigurationDefaultTemplateTest.java
File: IgniteCacheConfigurationDefaultTemplateTest.java
/** * @throws Exception If failed. */ public void testDefaultTemplate() throws Exception { Ignite ignite = startGrid(0); checkDefaultTemplate(ignite, "org.apache.ignite"); checkDefaultTemplate(ignite, "org.apache.ignite.templat"); checkDefaultTemplate(ignite, null); checkGetOrCreate(ignite, "org.apache.ignite.template", 3); CacheConfiguration templateCfg = new CacheConfiguration(); templateCfg.setBackups(4); ignite.addCacheConfiguration(templateCfg); checkGetOrCreate(ignite, "org.apache.ignite2", 4); }
27. GridCacheStoreValueBytesSelfTest#testEnabled()
Project: ignite
File: GridCacheStoreValueBytesSelfTest.java
File: GridCacheStoreValueBytesSelfTest.java
/** * JUnit. * * @throws Exception If failed. */ public void testEnabled() throws Exception { storeValBytes = true; Ignite g0 = startGrid(0); Ignite g1 = startGrid(1); IgniteCache<Integer, String> c = g0.cache(null); c.put(1, "Cached value"); GridCacheEntryEx entry = ((IgniteKernal) g1).internalCache().peekEx(1); assert entry != null; assert entry.valueBytes() != null; }
28. GridCachePartitionedProjectionAffinitySelfTest#testProjectionAffinity()
Project: ignite
File: GridCachePartitionedProjectionAffinitySelfTest.java
File: GridCachePartitionedProjectionAffinitySelfTest.java
/** @throws Exception If failed. */ @SuppressWarnings("deprecation") public void testProjectionAffinity() throws Exception { waitTopologyUpdate(); Ignite g0 = grid(0); Ignite g1 = grid(1); ClusterGroup g0Pinned = g0.cluster().forNodeIds(F.asList(g0.cluster().localNode().id())); ClusterGroup g01Pinned = g1.cluster().forNodeIds(F.asList(g0.cluster().localNode().id(), g1.cluster().localNode().id())); for (int i = 0; i < 100; i++) assertEquals(g0Pinned.ignite().affinity(null).mapKeyToNode(i).id(), g01Pinned.ignite().affinity(null).mapKeyToNode(i).id()); }
29. EventsExample#main()
Project: ignite
File: EventsExample.java
File: EventsExample.java
/** * Executes example. * * @param args Command line arguments, none required. * @throws Exception If example execution failed. */ public static void main(String[] args) throws Exception { try (Ignite ignite = Ignition.start("examples/config/example-ignite.xml")) { System.out.println(); System.out.println(">>> Events API example started."); // Listen to events happening on local node. localListen(); // Listen to events happening on all cluster nodes. remoteListen(); // Wait for a while while callback is notified about remaining puts. Thread.sleep(1000); } }
30. IgniteSetExample#main()
Project: ignite
File: IgniteSetExample.java
File: IgniteSetExample.java
/** * Executes example. * * @param args Command line arguments, none required. * @throws Exception If example execution failed. */ public static void main(String[] args) throws Exception { try (Ignite ignite = Ignition.start("examples/config/example-ignite.xml")) { System.out.println(); System.out.println(">>> Ignite set example started."); // Make set name. String setName = UUID.randomUUID().toString(); set = initializeSet(ignite, setName); writeToSet(ignite); clearAndRemoveSet(); } System.out.println("Ignite set example finished."); }
31. IgniteQueueExample#main()
Project: ignite
File: IgniteQueueExample.java
File: IgniteQueueExample.java
/** * Executes example. * * @param args Command line arguments, none required. * @throws Exception If example execution failed. */ public static void main(String[] args) throws Exception { try (Ignite ignite = Ignition.start("examples/config/example-ignite.xml")) { System.out.println(); System.out.println(">>> Ignite queue example started."); // Make queue name. String queueName = UUID.randomUUID().toString(); queue = initializeQueue(ignite, queueName); readFromQueue(ignite); writeToQueue(ignite); clearAndRemoveQueue(); } System.out.println("Cache queue example finished."); }
32. IgniteAtomicSequenceExample#main()
Project: ignite
File: IgniteAtomicSequenceExample.java
File: IgniteAtomicSequenceExample.java
/** * Executes example. * * @param args Command line arguments, none required. * @throws Exception If example execution failed. */ public static void main(String[] args) throws Exception { try (Ignite ignite = Ignition.start("examples/config/example-ignite.xml")) { System.out.println(); System.out.println(">>> Cache atomic sequence example started."); // Try increment atomic sequence on all cluster nodes. Note that this node is also part of the cluster. ignite.compute().broadcast(new SequenceClosure("example-sequence")); System.out.println(); System.out.println("Finished atomic sequence example..."); System.out.println("Check all nodes for output (this node is also part of the cluster)."); System.out.println(); } }
33. CacheLoadOnlyStoreExample#main()
Project: ignite
File: CacheLoadOnlyStoreExample.java
File: CacheLoadOnlyStoreExample.java
/** * Executes example. * * @param args Command line arguments, none required. * @throws IgniteException If example execution failed. */ public static void main(String[] args) throws IgniteException { try (Ignite ignite = Ignition.start("examples/config/example-ignite.xml")) { System.out.println(); System.out.println(">>> CacheLoadOnlyStoreExample started."); ProductLoader productLoader = new ProductLoader("examples/src/main/resources/person.csv"); productLoader.setThreadsCount(2); productLoader.setBatchSize(10); productLoader.setBatchQueueSize(1); try (IgniteCache<Long, Person> cache = ignite.getOrCreateCache(cacheConfiguration(productLoader))) { // load data. cache.loadCache(null); System.out.println(">>> Loaded number of items: " + cache.size(CachePeekMode.PRIMARY)); System.out.println(">>> Data for the person by id1: " + cache.get(1L)); } finally { // Distributed cache could be removed from cluster only by #destroyCache() call. ignite.destroyCache(CACHE_NAME); } } }
34. CacheEntryProcessorExample#main()
Project: ignite
File: CacheEntryProcessorExample.java
File: CacheEntryProcessorExample.java
/** * Executes example. * * @param args Command line arguments, none required. * @throws IgniteException If example execution failed. */ public static void main(String[] args) throws IgniteException { try (Ignite ignite = Ignition.start("examples/config/example-ignite.xml")) { System.out.println(); System.out.println(">>> Entry processor example started."); // Auto-close cache at the end of the example. try (IgniteCache<Integer, Integer> cache = ignite.getOrCreateCache(CACHE_NAME)) { // Demonstrates usage of EntryProcessor.invoke(...) method. populateEntriesWithInvoke(cache); // Demonstrates usage of EntryProcessor.invokeAll(...) method. incrementEntriesWithInvokeAll(cache); } finally { // Distributed cache could be removed from cluster only by #destroyCache() call. ignite.destroyCache(CACHE_NAME); } } }
35. CacheApiExample#main()
Project: ignite
File: CacheApiExample.java
File: CacheApiExample.java
/** * Executes example. * * @param args Command line arguments, none required. * @throws IgniteException If example execution failed. */ public static void main(String[] args) throws IgniteException { try (Ignite ignite = Ignition.start("examples/config/example-ignite.xml")) { System.out.println(); System.out.println(">>> Cache API example started."); // Auto-close cache at the end of the example. try (IgniteCache<Integer, String> cache = ignite.getOrCreateCache(CACHE_NAME)) { // Demonstrate atomic map operations. atomicMapOperations(cache); } finally { // Distributed cache could be removed from cluster only by #destroyCache() call. ignite.destroyCache(CACHE_NAME); } } }
36. CacheAffinityExample#visitUsingAffinityRun()
Project: ignite
File: CacheAffinityExample.java
File: CacheAffinityExample.java
/** * Collocates jobs with keys they need to work on using * {@link IgniteCompute#affinityRun(String, Object, IgniteRunnable)} method. */ private static void visitUsingAffinityRun() { Ignite ignite = Ignition.ignite(); final IgniteCache<Integer, String> cache = ignite.cache(CACHE_NAME); for (int i = 0; i < KEY_CNT; i++) { final int key = i; // This runnable will execute on the remote node where // data with the given key is located. Since it will be co-located // we can use local 'peek' operation safely. ignite.compute().affinityRun(CACHE_NAME, key, new IgniteRunnable() { @Override public void run() { // Peek is a local memory lookup, however, value should never be 'null' // as we are co-located with node that has a given key. System.out.println("Co-located using affinityRun [key= " + key + ", value=" + cache.localPeek(key) + ']'); } }); } }
37. CacheAffinityExample#main()
Project: ignite
File: CacheAffinityExample.java
File: CacheAffinityExample.java
/** * Executes example. * * @param args Command line arguments, none required. * @throws IgniteException If example execution failed. */ public static void main(String[] args) throws IgniteException { try (Ignite ignite = Ignition.start("examples/config/example-ignite.xml")) { System.out.println(); System.out.println(">>> Cache affinity example started."); // Auto-close cache at the end of the example. try (IgniteCache<Integer, String> cache = ignite.getOrCreateCache(CACHE_NAME)) { for (int i = 0; i < KEY_CNT; i++) cache.put(i, Integer.toString(i)); // Co-locates jobs with data using IgniteCompute.affinityRun(...) method. visitUsingAffinityRun(); // Co-locates jobs with data using IgniteCluster.mapKeysToNodes(...) method. visitUsingMapKeysToNodes(); } finally { // Distributed cache could be removed from cluster only by #destroyCache() call. ignite.destroyCache(CACHE_NAME); } } }
38. ComputeFailoverExample#main()
Project: ignite
File: ComputeFailoverExample.java
File: ComputeFailoverExample.java
/** * Executes example. * * @param args Command line arguments, none required. * @throws IgniteException If example execution failed. */ public static void main(String[] args) throws IgniteException { try (Ignite ignite = Ignition.start(ComputeFailoverNodeStartup.configuration())) { if (!ExamplesUtils.checkMinTopologySize(ignite.cluster(), 2)) return; System.out.println(); System.out.println("Compute failover example started."); // Number of letters. int charCnt = ignite.compute().apply(new CheckPointJob(), "Stage1 Stage2"); System.out.println(); System.out.println(">>> Finished executing fail-over example with checkpoints."); System.out.println(">>> Total number of characters in the phrase is '" + charCnt + "'."); System.out.println(">>> You should see exception stack trace from failed job on some node."); System.out.println(">>> Failed job will be failed over to another node."); } }
39. ComputeTaskSplitExample#main()
Project: ignite
File: ComputeTaskSplitExample.java
File: ComputeTaskSplitExample.java
/** * Executes example. * * @param args Command line arguments, none required. * @throws IgniteException If example execution failed. */ public static void main(String[] args) throws IgniteException { try (Ignite ignite = Ignition.start("examples/config/example-ignite.xml")) { System.out.println(); System.out.println("Compute task split example started."); // Execute task on the cluster and wait for its completion. int cnt = ignite.compute().execute(SplitExampleCharacterCountTask.class, "Hello Ignite Enabled World!"); System.out.println(); System.out.println(">>> Total number of characters in the phrase is '" + cnt + "'."); System.out.println(">>> Check all nodes for output (this node is also part of the cluster)."); } }
40. ComputeTaskMapExample#main()
Project: ignite
File: ComputeTaskMapExample.java
File: ComputeTaskMapExample.java
/** * Executes example. * * @param args Command line arguments, none required. * @throws IgniteException If example execution failed. */ public static void main(String[] args) throws IgniteException { try (Ignite ignite = Ignition.start("examples/config/example-ignite.xml")) { System.out.println(); System.out.println("Compute task map example started."); // Execute task on the cluster and wait for its completion. int cnt = ignite.compute().execute(MapExampleCharacterCountTask.class, "Hello Ignite Enabled World!"); System.out.println(); System.out.println(">>> Total number of characters in the phrase is '" + cnt + "'."); System.out.println(">>> Check all nodes for output (this node is also part of the cluster)."); } }
41. ComputeRunnableExample#main()
Project: ignite
File: ComputeRunnableExample.java
File: ComputeRunnableExample.java
/** * Executes example. * * @param args Command line arguments, none required. * @throws IgniteException If example execution failed. */ public static void main(String[] args) throws IgniteException { try (Ignite ignite = Ignition.start("examples/config/example-ignite.xml")) { System.out.println(); System.out.println("Compute runnable example started."); IgniteCompute compute = ignite.compute(); // Iterate through all words in the sentence and create runnable jobs. for (final String word : "Print words using runnable".split(" ")) { // Execute runnable on some node. compute.run(new IgniteRunnable() { @Override public void run() { System.out.println(); System.out.println(">>> Printing '" + word + "' on this node from ignite job."); } }); } System.out.println(); System.out.println(">>> Finished printing words using runnable execution."); System.out.println(">>> Check all nodes for output (this node is also part of the cluster)."); } }
42. ComputeBroadcastExample#main()
Project: ignite
File: ComputeBroadcastExample.java
File: ComputeBroadcastExample.java
/** * Executes example. * * @param args Command line arguments, none required. * @throws IgniteException If example execution failed. */ public static void main(String[] args) throws IgniteException { try (Ignite ignite = Ignition.start("examples/config/example-ignite.xml")) { System.out.println(); System.out.println(">>> Compute broadcast example started."); // Print hello message on all nodes. hello(ignite); // Gather system info from all nodes. gatherSystemInfo(ignite); } }
43. IgniteEventsEndpoint#createIgniteEvents()
Project: camel
File: IgniteEventsEndpoint.java
File: IgniteEventsEndpoint.java
private IgniteEvents createIgniteEvents() { Ignite ignite = ignite(); IgniteEvents events; if (clusterGroupExpression == null) { LOG.info("Ignite Events endpoint for event types {} using no Cluster Group.", this.events); events = ignite.events(); } else { ClusterGroup group = clusterGroupExpression.getClusterGroup(ignite); LOG.info("Ignite Events endpoint for event types {} using Cluster Group: {}.", this.events, group); events = ignite.events(group); } return events; }
44. IgniteComputeEndpoint#createIgniteCompute()
Project: camel
File: IgniteComputeEndpoint.java
File: IgniteComputeEndpoint.java
public IgniteCompute createIgniteCompute() { Ignite ignite = ignite(); IgniteCompute compute = clusterGroupExpression == null ? ignite.compute() : ignite.compute(clusterGroupExpression.getClusterGroup(ignite)); if (computeName != null) { compute = compute.withName(computeName); } if (timeoutMillis != null) { compute = compute.withTimeout(timeoutMillis); } return compute; }
45. IgniteClientReconnectAbstractTest#clientRouter()
Project: ignite
File: IgniteClientReconnectAbstractTest.java
File: IgniteClientReconnectAbstractTest.java
/** * @param client Client. * @return Server node client connected to. */ protected Ignite clientRouter(Ignite client) { TcpDiscoveryNode node = (TcpDiscoveryNode) client.cluster().localNode(); assertTrue(node.isClient()); assertNotNull(node.clientRouterNodeId()); Ignite srv = G.ignite(node.clientRouterNodeId()); assertNotNull(srv); return srv; }
46. GridTaskTimeoutSelfTest#testAsynchronousTimeout()
Project: ignite
File: GridTaskTimeoutSelfTest.java
File: GridTaskTimeoutSelfTest.java
/** * @throws Exception If failed. */ public void testAsynchronousTimeout() throws Exception { Ignite ignite = G.ignite(getTestGridName()); ignite.compute().localDeployTask(GridTaskTimeoutTestTask.class, GridTaskTimeoutTestTask.class.getClassLoader()); ComputeTaskFuture<?> fut = executeAsync(ignite.compute().withTimeout(TIMEOUT), GridTaskTimeoutTestTask.class.getName(), null); // Allow timed out events to be executed. Thread.sleep(TIMEOUT + 500); checkTimedOutEvents(fut.getTaskSession().getId()); }
47. GridTaskTimeoutSelfTest#testSynchronousTimeout()
Project: ignite
File: GridTaskTimeoutSelfTest.java
File: GridTaskTimeoutSelfTest.java
/** * @throws Exception If failed. */ public void testSynchronousTimeout() throws Exception { Ignite ignite = G.ignite(getTestGridName()); ignite.compute().localDeployTask(GridTaskTimeoutTestTask.class, GridTaskTimeoutTestTask.class.getClassLoader()); ComputeTaskFuture<?> fut = executeAsync(ignite.compute().withTimeout(TIMEOUT), GridTaskTimeoutTestTask.class.getName(), null); try { fut.get(); assert false : "ComputeTaskTimeoutException was not thrown (synchronous apply)"; } catch (ComputeTaskTimeoutException e) { info("Received expected timeout exception (synchronous apply): " + e); } Thread.sleep(TIMEOUT + 500); checkTimedOutEvents(fut.getTaskSession().getId()); }
48. GridTaskInstanceExecutionSelfTest#testSynchronousExecute()
Project: ignite
File: GridTaskInstanceExecutionSelfTest.java
File: GridTaskInstanceExecutionSelfTest.java
/** * @throws Exception If failed. */ public void testSynchronousExecute() throws Exception { Ignite ignite = G.ignite(getTestGridName()); testState = 12345; GridStatefulTask task = new GridStatefulTask(testState); assert task.getState() != null; assert task.getState() == testState; IgniteCompute comp = ignite.compute().withAsync(); assertNull(comp.execute(task, "testArg")); ComputeTaskFuture<?> fut = comp.future(); assert fut != null; info("Task result: " + fut.get()); }
49. GridTaskFailoverSelfTest#testFailover()
Project: ignite
File: GridTaskFailoverSelfTest.java
File: GridTaskFailoverSelfTest.java
/** * @throws Exception If test failed. */ @SuppressWarnings("unchecked") public void testFailover() throws Exception { Ignite ignite = startGrid(); try { ignite.compute().localDeployTask(GridFailoverTestTask.class, GridFailoverTestTask.class.getClassLoader()); ComputeTaskFuture<?> fut = ignite.compute().execute(GridFailoverTestTask.class.getName(), null); assert fut != null; fut.get(); assert false : "Should never be reached due to exception thrown."; } catch (ClusterTopologyException e) { info("Received correct exception: " + e); } finally { stopGrid(); } }
50. GridTaskExecutionContextSelfTest#testWithNoFailoverTask()
Project: ignite
File: GridTaskExecutionContextSelfTest.java
File: GridTaskExecutionContextSelfTest.java
/** * @throws Exception If failed. */ public void testWithNoFailoverTask() throws Exception { final Ignite g = grid(0); GridTestUtils.assertThrows(log, new Callable<Object>() { @Override public Object call() throws Exception { g.compute().withNoFailover().execute(new TestTask(true), null); return null; } }, ComputeExecutionRejectedException.class, "Expected error."); assertEquals(1, CNT.get()); }
51. GridTaskExecutionContextSelfTest#testWithName()
Project: ignite
File: GridTaskExecutionContextSelfTest.java
File: GridTaskExecutionContextSelfTest.java
/** * @throws Exception If failed. */ public void testWithName() throws Exception { IgniteCallable<String> f = new IgniteCallable<String>() { @TaskSessionResource private ComputeTaskSession ses; @Override public String call() { return ses.getTaskName(); } }; Ignite g = grid(0); assert "name1".equals(g.compute().withName("name1").call(f)); assert "name2".equals(g.compute().withName("name2").call(f)); assert f.getClass().getName().equals(g.compute().call(f)); assert "name1".equals(g.compute().withName("name1").execute(new TestTask(false), null)); assert "name2".equals(g.compute().withName("name2").execute(new TestTask(false), null)); assert TestTask.class.getName().equals(g.compute().execute(new TestTask(false), null)); }
52. GridNodeVisorAttributesSelfTest#startGridAndCheck()
Project: ignite
File: GridNodeVisorAttributesSelfTest.java
File: GridNodeVisorAttributesSelfTest.java
/** * Start grid node and ensure that Visor-related node attributes are set properly. * * @throws Exception If grid start failed. */ private void startGridAndCheck() throws Exception { Ignite g = startGrid(); Map<String, Object> attrs = g.cluster().localNode().attributes(); for (String prop : SYSTEM_PROPS) { assert attrs.containsKey(prop); assertEquals(System.getProperty(prop), attrs.get(prop)); } for (String prop : IGNITE_PROPS) assert attrs.containsKey(prop); }
53. GridNodeLocalSelfTest#testNodeLocal()
Project: ignite
File: GridNodeLocalSelfTest.java
File: GridNodeLocalSelfTest.java
/** * Test node-local values operations. * * @throws Exception If test failed. */ public void testNodeLocal() throws Exception { Ignite g = G.ignite(getTestGridName()); String keyStr = "key"; int keyNum = 1; Date keyDate = new Date(); GridTuple3 key = F.t(keyNum, keyStr, keyDate); ConcurrentMap<Object, Object> nl = g.cluster().nodeLocalMap(); nl.put(keyStr, "Hello world!"); nl.put(key, 12); assert nl.containsKey(keyStr); assert nl.containsKey(key); assert !nl.containsKey(keyNum); assert !nl.containsKey(F.t(keyNum, keyStr)); assert "Hello world!".equals(nl.get(keyStr)); assert (Integer) nl.get(key) == 12; }
54. GridJobStealingSelfTest#testProjectionPredicateInternalStealing()
Project: ignite
File: GridJobStealingSelfTest.java
File: GridJobStealingSelfTest.java
/** * Tests that projection predicate is taken into account by Stealing SPI, * and that jobs in projection can steal tasks from each other. * * @throws Exception If failed. */ public void testProjectionPredicateInternalStealing() throws Exception { final Ignite ignite3 = startGrid(3); IgnitePredicate<ClusterNode> p = new P1<ClusterNode>() { @Override public boolean apply(ClusterNode e) { return ignite1.cluster().localNode().id().equals(e.id()) || // Limit projection with only grid1 or grid3 node. ignite3.cluster().localNode().id().equals(e.id()); } }; executeAsync(compute(ignite1.cluster().forPredicate(p)), new JobStealingSingleNodeTask(4), null).get(TASK_EXEC_TIMEOUT_MS); // Verify that jobs were run only on grid1 and grid3 (not on grid2) assertEquals(2, jobDistrMap.keySet().size()); assertFalse(jobDistrMap.containsKey(ignite2.cluster().localNode().id())); }
55. GridJobStealingSelfTest#testProjectionPredicate()
Project: ignite
File: GridJobStealingSelfTest.java
File: GridJobStealingSelfTest.java
/** * Tests that projection predicate is taken into account by Stealing SPI. * * @throws Exception If failed. */ public void testProjectionPredicate() throws Exception { final Ignite ignite3 = startGrid(3); executeAsync(compute(ignite1.cluster().forPredicate(new P1<ClusterNode>() { @Override public boolean apply(ClusterNode e) { return ignite1.cluster().localNode().id().equals(e.id()) || // Limit projection with only grid1 or grid3 node. ignite3.cluster().localNode().id().equals(e.id()); } })), new JobStealingSpreadTask(4), null).get(TASK_EXEC_TIMEOUT_MS); // Verify that jobs were run only on grid1 and grid3 (not on grid2) assertEquals(2, jobDistrMap.keySet().size()); assertEquals(2, jobDistrMap.get(ignite1.cluster().localNode().id()).size()); assertEquals(2, jobDistrMap.get(ignite3.cluster().localNode().id()).size()); assertFalse(jobDistrMap.containsKey(ignite2.cluster().localNode().id())); }
56. GridJobContextSelfTest#testJobContext()
Project: ignite
File: GridJobContextSelfTest.java
File: GridJobContextSelfTest.java
/** * @throws Exception If anything failed. */ public void testJobContext() throws Exception { Ignite ignite = startGrid(1); try { startGrid(2); try { ignite.compute().execute(JobContextTask.class, null); } finally { stopGrid(2); } } finally { stopGrid(1); } }
57. GridDeploymentSelfTest#testIgnoreDeploymentSpi()
Project: ignite
File: GridDeploymentSelfTest.java
File: GridDeploymentSelfTest.java
/** * @throws Exception If failed. */ public void testIgnoreDeploymentSpi() throws Exception { // If peer class loading is disabled and local deployment SPI // is configured, SPI should be ignored. p2pEnabled = false; Ignite ignite = startGrid(getTestGridName()); try { ignite.compute().localDeployTask(GridDeploymentTestTask.class, GridDeploymentTestTask.class.getClassLoader()); assert depSpi.getRegisterCount() == 0 : "Invalid deploy count: " + depSpi.getRegisterCount(); assert depSpi.getUnregisterCount() == 0 : "Invalid undeploy count: " + depSpi.getUnregisterCount(); ignite.compute().undeployTask(GridDeploymentTestTask.class.getName()); assert depSpi.getRegisterCount() == 0 : "Invalid deploy count: " + depSpi.getRegisterCount(); assert depSpi.getUnregisterCount() == 0 : "Invalid undeploy count: " + depSpi.getUnregisterCount(); } finally { stopGrid(ignite); } }
58. GridDeploymentSelfTest#testDeploy()
Project: ignite
File: GridDeploymentSelfTest.java
File: GridDeploymentSelfTest.java
/** * @throws Exception If failed. */ public void testDeploy() throws Exception { Ignite ignite = startGrid(getTestGridName()); try { ignite.compute().localDeployTask(GridDeploymentTestTask.class, GridDeploymentTestTask.class.getClassLoader()); assert depSpi.getRegisterCount() == 1 : "Invalid deploy count: " + depSpi.getRegisterCount(); assert depSpi.getUnregisterCount() == 0 : "Invalid undeploy count: " + depSpi.getUnregisterCount(); assert ignite.compute().localTasks().get(GridDeploymentTestTask.class.getName()) != null; ignite.compute().undeployTask(GridDeploymentTestTask.class.getName()); assert depSpi.getRegisterCount() == 1 : "Invalid deploy count: " + depSpi.getRegisterCount(); assert depSpi.getUnregisterCount() == 1 : "Invalid undeploy count: " + depSpi.getUnregisterCount(); assert checkUndeployed(ignite, GridDeploymentTestTask.class.getName()); } finally { stopGrid(ignite); } }
59. GridComputationBinarylizableClosuresSelfTest#testMasterLeaveAwareRunnable()
Project: ignite
File: GridComputationBinarylizableClosuresSelfTest.java
File: GridComputationBinarylizableClosuresSelfTest.java
/** * Test that Binarylizable IgniteRunnable with ComputeJobMasterLeaveAware interface is serialized * using BinaryMarshaller. * * @throws Exception If failed. */ public void testMasterLeaveAwareRunnable() throws Exception { Ignite ignite = startGrid(1); startGrid(2); final TestBinarylizableMasterLeaveAwareRunnable runnable = new TestBinarylizableMasterLeaveAwareRunnable(); ignite.compute(ignite.cluster().forRemotes()).run(runnable); assert TestBinarylizableRunnable.executed.get(); assert TestBinarylizableRunnable.writeCalled.get(); assert TestBinarylizableRunnable.readCalled.get(); assert TestBinarylizableMasterLeaveAwareRunnable.writeCalled.get(); assert TestBinarylizableMasterLeaveAwareRunnable.readCalled.get(); }
60. GridComputationBinarylizableClosuresSelfTest#testRunnable()
Project: ignite
File: GridComputationBinarylizableClosuresSelfTest.java
File: GridComputationBinarylizableClosuresSelfTest.java
/** * Test that Binarylizable IgniteRunnable is serialized using BinaryMarshaller. * * @throws Exception If failed. */ public void testRunnable() throws Exception { Ignite ignite = startGrid(1); startGrid(2); final TestBinarylizableRunnable runnable = new TestBinarylizableRunnable(); ignite.compute(ignite.cluster().forRemotes()).run(runnable); assert TestBinarylizableRunnable.executed.get(); assert TestBinarylizableRunnable.writeCalled.get(); assert TestBinarylizableRunnable.readCalled.get(); }
61. GridComputationBinarylizableClosuresSelfTest#testMasterLeaveAwareCallable()
Project: ignite
File: GridComputationBinarylizableClosuresSelfTest.java
File: GridComputationBinarylizableClosuresSelfTest.java
/** * Test that Binarylizable IgniteCallable with ComputeJobMasterLeaveAware interface is serialized * using BinaryMarshaller. * * @throws Exception If failed. */ public void testMasterLeaveAwareCallable() throws Exception { Ignite ignite = startGrid(1); startGrid(2); final TestBinarylizableMasterLeaveAwareCallable callable = new TestBinarylizableMasterLeaveAwareCallable(); ignite.compute(ignite.cluster().forRemotes()).call(callable); assert TestBinarylizableCallable.executed.get(); assert TestBinarylizableCallable.writeCalled.get(); assert TestBinarylizableCallable.readCalled.get(); assert TestBinarylizableMasterLeaveAwareCallable.writeCalled.get(); assert TestBinarylizableMasterLeaveAwareCallable.readCalled.get(); }
62. GridComputationBinarylizableClosuresSelfTest#testCallable()
Project: ignite
File: GridComputationBinarylizableClosuresSelfTest.java
File: GridComputationBinarylizableClosuresSelfTest.java
/** * Test that Binarylizable IgniteCallable is serialized using BinaryMarshaller. * * @throws Exception If failed. */ public void testCallable() throws Exception { Ignite ignite = startGrid(1); startGrid(2); final TestBinarylizableCallable callable = new TestBinarylizableCallable(); ignite.compute(ignite.cluster().forRemotes()).call(callable); assert TestBinarylizableCallable.executed.get(); assert TestBinarylizableCallable.writeCalled.get(); assert TestBinarylizableCallable.readCalled.get(); }
63. GridComputationBinarylizableClosuresSelfTest#testMasterLeaveAwareJob()
Project: ignite
File: GridComputationBinarylizableClosuresSelfTest.java
File: GridComputationBinarylizableClosuresSelfTest.java
/** * Test that Binarylizable IgniteClosure with ComputeJobMasterLeaveAware interface is serialized * using BinaryMarshaller. * * @throws Exception If failed. */ public void testMasterLeaveAwareJob() throws Exception { Ignite ignite = startGrid(1); startGrid(2); final TestBinarylizableMasterLeaveAwareClosure job = new TestBinarylizableMasterLeaveAwareClosure(); ignite.compute(ignite.cluster().forRemotes()).apply(job, new TestBinarylizableObject()); assert TestBinarylizableClosure.executed.get(); assert TestBinarylizableClosure.writeCalled.get(); assert TestBinarylizableClosure.readCalled.get(); assert TestBinarylizableMasterLeaveAwareClosure.writeCalled.get(); assert TestBinarylizableMasterLeaveAwareClosure.readCalled.get(); assert TestBinarylizableObject.writeCalled.get(); assert TestBinarylizableObject.readCalled.get(); }
64. GridComputationBinarylizableClosuresSelfTest#testJob()
Project: ignite
File: GridComputationBinarylizableClosuresSelfTest.java
File: GridComputationBinarylizableClosuresSelfTest.java
/** * Test that Binarylizable IgniteClosure is serialized using BinaryMarshaller. * * @throws Exception If failed. */ public void testJob() throws Exception { Ignite ignite = startGrid(1); startGrid(2); final TestBinarylizableClosure closure = new TestBinarylizableClosure(); ignite.compute(ignite.cluster().forRemotes()).apply(closure, new TestBinarylizableObject()); assert TestBinarylizableClosure.executed.get(); assert TestBinarylizableClosure.writeCalled.get(); assert TestBinarylizableClosure.readCalled.get(); assert TestBinarylizableObject.writeCalled.get(); assert TestBinarylizableObject.readCalled.get(); }
65. GridCancelOnGridStopSelfTest#testCancelingJob()
Project: ignite
File: GridCancelOnGridStopSelfTest.java
File: GridCancelOnGridStopSelfTest.java
/** * @throws Exception If failed. */ public void testCancelingJob() throws Exception { cancelCall = false; try (Ignite g = startGrid(1)) { cnt = new CountDownLatch(1); g.compute().withAsync().execute(CancelledTask.class, null); cnt.await(); } assert cancelCall; }
66. GridAlwaysFailoverSpiFailSelfTest#testNoneFailoverTask()
Project: ignite
File: GridAlwaysFailoverSpiFailSelfTest.java
File: GridAlwaysFailoverSpiFailSelfTest.java
/** * @throws Exception If failed. */ @SuppressWarnings({ "UnusedCatchParameter", "ThrowableInstanceNeverThrown" }) public void testNoneFailoverTask() throws Exception { isFailoverCalled = false; Ignite ignite = G.ignite(getTestGridName()); ignite.compute().localDeployTask(GridTestFailoverTask.class, GridTestFailoverTask.class.getClassLoader()); try { ignite.compute().execute(GridTestFailoverTask.class.getName(), new IgniteException("Task should NOT be failed over")); assert false; } catch (IgniteException e) { } assert !isFailoverCalled; }
67. GridAlwaysFailoverSpiFailSelfTest#testFailoverTask()
Project: ignite
File: GridAlwaysFailoverSpiFailSelfTest.java
File: GridAlwaysFailoverSpiFailSelfTest.java
/** * @throws Exception If failed. */ @SuppressWarnings({ "UnusedCatchParameter", "ThrowableInstanceNeverThrown" }) public void testFailoverTask() throws Exception { isFailoverCalled = false; Ignite ignite = G.ignite(getTestGridName()); ignite.compute().localDeployTask(GridTestFailoverTask.class, GridTestFailoverTask.class.getClassLoader()); try { ignite.compute().execute(GridTestFailoverTask.class.getName(), new ComputeExecutionRejectedException("Task should be failed over")); assert false; } catch (IgniteException e) { } assert isFailoverCalled; }
68. ClusterGroupSelfTest#testAgeClusterGroupSerialization()
Project: ignite
File: ClusterGroupSelfTest.java
File: ClusterGroupSelfTest.java
/** * @throws Exception If failed. */ public void testAgeClusterGroupSerialization() throws Exception { Marshaller marshaller = getConfiguration().getMarshaller(); ClusterGroup grp = ignite.cluster().forYoungest(); ClusterNode node = grp.node(); byte[] arr = marshaller.marshal(grp); ClusterGroup obj = marshaller.unmarshal(arr, null); assertEquals(node.id(), obj.node().id()); try (Ignite ignore = startGrid()) { obj = marshaller.unmarshal(arr, null); assertEquals(grp.node().id(), obj.node().id()); assertFalse(node.id().equals(obj.node().id())); } }
69. ClusterGroupSelfTest#testNewNodes()
Project: ignite
File: ClusterGroupSelfTest.java
File: ClusterGroupSelfTest.java
/** * @throws Exception If failed. */ public void testNewNodes() throws Exception { ClusterGroup youngest = ignite.cluster().forYoungest(); ClusterGroup oldest = ignite.cluster().forOldest(); ClusterNode old = oldest.node(); ClusterNode last = youngest.node(); assertNotNull(last); try (Ignite g = startGrid(NODES_CNT)) { ClusterNode n = g.cluster().localNode(); ClusterNode latest = youngest.node(); assertNotNull(latest); assertEquals(latest.id(), n.id()); assertEquals(oldest.node(), old); } }
70. ClusterGroupSelfTest#testForDaemons()
Project: ignite
File: ClusterGroupSelfTest.java
File: ClusterGroupSelfTest.java
/** * @throws Exception If failed. */ public void testForDaemons() throws Exception { assertEquals(4, ignite.cluster().nodes().size()); ClusterGroup daemons = ignite.cluster().forDaemons(); ClusterGroup srvs = ignite.cluster().forServers(); assertEquals(0, daemons.nodes().size()); assertEquals(2, srvs.nodes().size()); Ignition.setDaemon(true); try (Ignite g = startGrid(NODES_CNT)) { Ignition.setDaemon(false); try (Ignite g1 = startGrid(NODES_CNT + 1)) { assertEquals(1, ignite.cluster().forDaemons().nodes().size()); assertEquals(3, srvs.nodes().size()); assertEquals(1, daemons.nodes().size()); } } }
71. ClusterGroupHostsSelfTest#testHostNames()
Project: ignite
File: ClusterGroupHostsSelfTest.java
File: ClusterGroupHostsSelfTest.java
/** * @throws Exception If failed. */ public void testHostNames() throws Exception { Ignite ignite = grid(); Collection<String> locNodeHosts = ignite.cluster().localNode().hostNames(); Collection<String> clusterHosts = ignite.cluster().hostNames(); assertTrue(F.eqNotOrdered(locNodeHosts, clusterHosts)); boolean gotNpe = false; try { clusterHosts.add("valueShouldNotToBeAdded"); } catch (UnsupportedOperationException e) { gotNpe = true; } finally { assertTrue(gotNpe); } }
72. ClusterGroupHostsSelfTest#testForHosts()
Project: ignite
File: ClusterGroupHostsSelfTest.java
File: ClusterGroupHostsSelfTest.java
/** * @throws Exception If failed. */ public void testForHosts() throws Exception { Ignite ignite = grid(); assertEquals(1, ignite.cluster().forHost("h_1").nodes().size()); assertEquals(1, ignite.cluster().forHost("h_1", "h_3").nodes().size()); assertEquals(1, ignite.cluster().forHost("unknown_host", "h_2").nodes().size()); assertEquals(1, ignite.cluster().forHost("h_1", "h_3", "unknown_host", "h_2").nodes().size()); assertEquals(0, ignite.cluster().forHost("unknown_host").nodes().size()); boolean gotNpe = false; try { assertEquals(0, ignite.cluster().forHost(null, null, null).nodes().size()); } catch (NullPointerException e) { gotNpe = true; } finally { assertTrue(gotNpe); } }
73. GridBinaryAffinityKeySelfTest#testAffinity()
Project: ignite
File: GridBinaryAffinityKeySelfTest.java
File: GridBinaryAffinityKeySelfTest.java
/** * @throws Exception If failed. */ public void testAffinity() throws Exception { checkAffinity(grid(0)); try (Ignite igniteNoCache = startGrid(GRID_CNT)) { try { igniteNoCache.cache(null); } catch (IllegalArgumentException ignore) { } checkAffinity(igniteNoCache); } }
74. GridCacheJdbcBlobStoreMultithreadedSelfTest#checkOpenedClosedCount()
Project: ignite
File: GridCacheJdbcBlobStoreMultithreadedSelfTest.java
File: GridCacheJdbcBlobStoreMultithreadedSelfTest.java
/** * */ private void checkOpenedClosedCount() { assertEquals(GRID_CNT, Ignition.allGrids().size()); for (Ignite ignite : Ignition.allGrids()) { GridCacheContext cctx = ((IgniteKernal) ignite).internalCache().context(); CacheStore store = cctx.store().configuredStore(); long opened = ((LongAdder8) U.field(store, "opened")).sum(); long closed = ((LongAdder8) U.field(store, "closed")).sum(); assert opened > 0; assert closed > 0; assertEquals(opened, closed); } }
75. AffinityFunctionExcludeNeighborsAbstractSelfTest#testAffinitySingleNode()
Project: ignite
File: AffinityFunctionExcludeNeighborsAbstractSelfTest.java
File: AffinityFunctionExcludeNeighborsAbstractSelfTest.java
/** * @throws Exception If failed. */ public void testAffinitySingleNode() throws Exception { Ignite g = startGrid(); try { Object key = 12345; Collection<? extends ClusterNode> affNodes = nodes(g.affinity(null), key); info("Affinity picture for grid: " + U.toShortString(affNodes)); assertEquals(1, affNodes.size()); } finally { stopAllGrids(); } }
76. AffinityClientNodeSelfTest#checkCache()
Project: ignite
File: AffinityClientNodeSelfTest.java
File: AffinityClientNodeSelfTest.java
/** * @param cacheName Cache name. * @param expNodes Expected number of nodes per partition. */ private void checkCache(String cacheName, int expNodes) { log.info("Test cache: " + cacheName); Ignite client = ignite(NODE_CNT - 1); assertTrue(client.configuration().isClientMode()); ClusterNode clientNode = client.cluster().localNode(); for (int i = 0; i < NODE_CNT; i++) { Ignite ignite = ignite(i); Affinity<Integer> aff = ignite.affinity(cacheName); for (int part = 0; part < aff.partitions(); part++) { Collection<ClusterNode> nodes = aff.mapPartitionToPrimaryAndBackups(part); assertEquals(expNodes, nodes.size()); assertFalse(nodes.contains(clientNode)); } } }
77. TcpDiscoveryIpFinderAdapter#discoveryClientMode()
Project: ignite
File: TcpDiscoveryIpFinderAdapter.java
File: TcpDiscoveryIpFinderAdapter.java
/** * @return {@code True} if TCP discovery works in client mode. */ protected boolean discoveryClientMode() { boolean clientMode; Ignite ignite0 = ignite; if (ignite0 != null) { // Can be null if used in tests without starting Ignite. DiscoverySpi discoSpi = ignite0.configuration().getDiscoverySpi(); if (!(discoSpi instanceof TcpDiscoverySpi)) throw new IgniteSpiException("TcpDiscoveryIpFinder should be used with TcpDiscoverySpi: " + discoSpi); clientMode = ignite0.configuration().isClientMode() && !((TcpDiscoverySpi) discoSpi).isForceServerMode(); } else clientMode = false; return clientMode; }
78. JdbcNoDefaultCacheTest#beforeTestsStarted()
Project: ignite
File: JdbcNoDefaultCacheTest.java
File: JdbcNoDefaultCacheTest.java
/** {@inheritDoc} */ @Override protected void beforeTestsStarted() throws Exception { startGridsMultiThreaded(GRID_CNT); Class.forName("org.apache.ignite.IgniteJdbcDriver"); Ignite ignite = ignite(0); IgniteCache<Integer, Integer> cache1 = ignite.cache(CACHE1_NAME); IgniteCache<Integer, Integer> cache2 = ignite.cache(CACHE2_NAME); for (int i = 0; i < 10; i++) { cache1.put(i, i * 2); cache2.put(i, i * 3); } }
79. TaskEventSubjectIdSelfTest#beforeTestsStarted()
Project: ignite
File: TaskEventSubjectIdSelfTest.java
File: TaskEventSubjectIdSelfTest.java
@Override protected void beforeTestsStarted() throws Exception { Ignite g = startGrid(); g.events().localListen(new IgnitePredicate<Event>() { @Override public boolean apply(Event evt) { assert evt instanceof TaskEvent; evts.add((TaskEvent) evt); latch.countDown(); return true; } }, EVTS_TASK_EXECUTION); nodeId = g.cluster().localNode().id(); GridClientConfiguration cfg = new GridClientConfiguration(); cfg.setServers(Collections.singleton("127.0.0.1:11211")); client = GridClientFactory.start(cfg); }
80. ClientMemcachedProtocolSelfTest#testCustomPort()
Project: ignite
File: ClientMemcachedProtocolSelfTest.java
File: ClientMemcachedProtocolSelfTest.java
/** * @throws Exception If failed. */ public void testCustomPort() throws Exception { customPort = 11212; Ignite g = startGrid(); assert g != null; assert g.cluster().nodes().size() == gridCount() + 1; MemcachedClientIF c = startClient(); Assert.assertTrue(c.set("key", 0, 1).get()); Assert.assertEquals(1, c.get("key")); c.shutdown(); stopGrid(); }
81. JdbcNoDefaultCacheTest#beforeTestsStarted()
Project: ignite
File: JdbcNoDefaultCacheTest.java
File: JdbcNoDefaultCacheTest.java
/** {@inheritDoc} */ @Override protected void beforeTestsStarted() throws Exception { startGridsMultiThreaded(GRID_CNT); Class.forName("org.apache.ignite.IgniteJdbcDriver"); Ignite ignite = ignite(0); IgniteCache<Integer, Integer> cache1 = ignite.cache(CACHE1_NAME); IgniteCache<Integer, Integer> cache2 = ignite.cache(CACHE2_NAME); for (int i = 0; i < 10; i++) { cache1.put(i, i * 2); cache2.put(i, i * 3); } }
82. ClientStartNodeTask#main()
Project: ignite
File: ClientStartNodeTask.java
File: ClientStartNodeTask.java
/** * Example for start/stop node tasks. * * @param args Not used. */ public static void main(String[] args) { String nodeType = "tcp+ssl"; // Start initial node = 1 try (Ignite g = G.start(NODE_CFG.get(nodeType))) { // Change topology. changeTopology(g, 4, 1, nodeType); changeTopology(g, 1, 4, nodeType); // Stop node by id = 0 g.compute().execute(ClientStopNodeTask.class, g.cluster().localNode().id().toString()); assert G.allGrids().isEmpty(); } catch (Exception e) { System.err.println("Uncaught exception: " + e.getMessage()); e.printStackTrace(System.err); } }
83. ClientStartNodeTask#executeJob()
Project: ignite
File: ClientStartNodeTask.java
File: ClientStartNodeTask.java
/** {@inheritDoc} */ @Override protected Object executeJob(int gridSize, String type) { log.info(">>> Starting new grid node [currGridSize=" + gridSize + ", arg=" + type + "]"); if (type == null) throw new IllegalArgumentException("Node type to start should be specified."); IgniteConfiguration cfg = getConfig(type); // Generate unique for this VM grid name. String gridName = cfg.getGridName() + " (" + UUID.randomUUID() + ")"; // Update grid name (required to be unique). cfg.setGridName(gridName); // Start new node in current VM. Ignite g = G.start(cfg); log.info(">>> Grid started [nodeId=" + g.cluster().localNode().id() + ", name='" + g.name() + "']"); return true; }
84. IgniteCamelStreamerTest#subscribeToPutEvents()
Project: ignite
File: IgniteCamelStreamerTest.java
File: IgniteCamelStreamerTest.java
/** * Subscribe to cache put events. */ private CountDownLatch subscribeToPutEvents(int expect) { Ignite ignite = grid(); // Listen to cache PUT events and expect as many as messages as test data items final CountDownLatch latch = new CountDownLatch(expect); @SuppressWarnings("serial") IgniteBiPredicate<UUID, CacheEvent> callback = new IgniteBiPredicate<UUID, CacheEvent>() { @Override public boolean apply(UUID uuid, CacheEvent evt) { latch.countDown(); return true; } }; remoteLsnr = ignite.events(ignite.cluster().forCacheNodes(null)).remoteListen(callback, null, EVT_CACHE_OBJECT_PUT); return latch; }
85. EventsExample#localListen()
Project: ignite
File: EventsExample.java
File: EventsExample.java
/** * Listen to events that happen only on local node. * * @throws IgniteException If failed. */ private static void localListen() throws IgniteException { System.out.println(); System.out.println(">>> Local event listener example."); Ignite ignite = Ignition.ignite(); IgnitePredicate<TaskEvent> lsnr = evt -> { System.out.println("Received task event [evt=" + evt.name() + ", taskName=" + evt.taskName() + ']'); return true; }; // Register event listener for all local task execution events. ignite.events().localListen(lsnr, EVTS_TASK_EXECUTION); // Generate task events. ignite.compute().withName("example-event-task").run(() -> System.out.println("Executing sample job.")); // Unsubscribe local task event listener. ignite.events().stopLocalListen(lsnr); }
86. EventsExample#main()
Project: ignite
File: EventsExample.java
File: EventsExample.java
/** * Executes example. * * @param args Command line arguments, none required. * @throws Exception If example execution failed. */ public static void main(String[] args) throws Exception { try (Ignite ignite = Ignition.start("examples/config/example-ignite.xml")) { System.out.println(); System.out.println(">>> Events API example started."); // Listen to events happening on local node. localListen(); // Listen to events happening on all cluster nodes. remoteListen(); // Wait for a while while callback is notified about remaining puts. Thread.sleep(1000); } }
87. CacheEntryProcessorExample#main()
Project: ignite
File: CacheEntryProcessorExample.java
File: CacheEntryProcessorExample.java
/** * Executes example. * * @param args Command line arguments, none required. * @throws IgniteException If example execution failed. */ public static void main(String[] args) throws IgniteException { try (Ignite ignite = Ignition.start("examples/config/example-ignite.xml")) { System.out.println(); System.out.println(">>> Entry processor example started."); // Auto-close cache at the end of the example. try (IgniteCache<Integer, Integer> cache = ignite.getOrCreateCache(CACHE_NAME)) { // Demonstrates usage of EntryProcessor.invoke(...) method. populateEntriesWithInvoke(cache); // Demonstrates usage of EntryProcessor.invokeAll(...) method. incrementEntriesWithInvokeAll(cache); } finally { // Distributed cache could be removed from cluster only by #destroyCache() call. ignite.destroyCache(CACHE_NAME); } } }
88. CacheApiExample#main()
Project: ignite
File: CacheApiExample.java
File: CacheApiExample.java
/** * Executes example. * * @param args Command line arguments, none required. * @throws IgniteException If example execution failed. */ public static void main(String[] args) throws IgniteException { try (Ignite ignite = Ignition.start("examples/config/example-ignite.xml")) { System.out.println(); System.out.println(">>> Cache API example started."); CacheConfiguration<Integer, String> cfg = new CacheConfiguration<>(); cfg.setCacheMode(CacheMode.PARTITIONED); cfg.setName(CACHE_NAME); // Auto-close cache at the end of the example. try (IgniteCache<Integer, String> cache = ignite.getOrCreateCache(cfg)) { // Demonstrate atomic map operations. atomicMapOperations(cache); } finally { // Distributed cache could be removed from cluster only by #destroyCache() call. ignite.destroyCache(CACHE_NAME); } } }
89. CacheAffinityExample#visitUsingAffinityRun()
Project: ignite
File: CacheAffinityExample.java
File: CacheAffinityExample.java
/** * Collocates jobs with keys they need to work on using * {@link IgniteCompute#affinityRun(String, Object, IgniteRunnable)} method. */ private static void visitUsingAffinityRun() { Ignite ignite = Ignition.ignite(); final IgniteCache<Integer, String> cache = ignite.cache(CACHE_NAME); for (int i = 0; i < KEY_CNT; i++) { int key = i; // This runnable will execute on the remote node where // data with the given key is located. Since it will be co-located // we can use local 'peek' operation safely. ignite.compute().affinityRun(CACHE_NAME, key, () -> System.out.println("Co-located using affinityRun [key= " + key + ", value=" + cache.localPeek(key) + ']')); } }
90. ComputeRunnableExample#main()
Project: ignite
File: ComputeRunnableExample.java
File: ComputeRunnableExample.java
/** * Executes example. * * @param args Command line arguments, none required. * @throws IgniteException If example execution failed. */ public static void main(String[] args) throws IgniteException { try (Ignite ignite = Ignition.start("examples/config/example-ignite.xml")) { System.out.println(); System.out.println("Compute runnable example started."); IgniteCompute compute = ignite.compute(); // Iterate through all words in the sentence and create runnable jobs. for (final String word : "Print words using runnable".split(" ")) { // Execute runnable on some node. compute.run(() -> { System.out.println(); System.out.println(">>> Printing '" + word + "' on this node from ignite job."); }); } System.out.println(); System.out.println(">>> Finished printing words using runnable execution."); System.out.println(">>> Check all nodes for output (this node is also part of the cluster)."); } }
91. ComputeClosureExample#main()
Project: ignite
File: ComputeClosureExample.java
File: ComputeClosureExample.java
/** * Executes example. * * @param args Command line arguments, none required. * @throws IgniteException If example execution failed. */ public static void main(String[] args) throws IgniteException { try (Ignite ignite = Ignition.start("examples/config/example-ignite.xml")) { System.out.println(); System.out.println(">>> Compute closure example started."); // Execute closure on all cluster nodes. Collection<Integer> res = ignite.compute().apply((String word) -> { System.out.println(); System.out.println(">>> Printing '" + word + "' on this node from ignite job."); // Return number of letters in the word. return word.length(); }, // Job parameters. Ignite will create as many jobs as there are parameters. Arrays.asList("Count characters using closure".split(" "))); int sum = res.stream().mapToInt( i -> i).sum(); System.out.println(); System.out.println(">>> Total number of characters in the phrase is '" + sum + "'."); System.out.println(">>> Check all nodes for output (this node is also part of the cluster)."); } }
92. ComputeBroadcastExample#main()
Project: ignite
File: ComputeBroadcastExample.java
File: ComputeBroadcastExample.java
/** * Executes example. * * @param args Command line arguments, none required. * @throws IgniteException If example execution failed. */ public static void main(String[] args) throws IgniteException { try (Ignite ignite = Ignition.start("examples/config/example-ignite.xml")) { System.out.println(); System.out.println(">>> Compute broadcast example started."); // Print hello message on all nodes. hello(ignite); // Gather system info from all nodes. gatherSystemInfo(ignite); } }
93. LifecycleExample#main()
Project: ignite
File: LifecycleExample.java
File: LifecycleExample.java
/** * Executes example. * * @param args Command line arguments, none required. * @throws IgniteException If example execution failed. */ public static void main(String[] args) throws IgniteException { System.out.println(); System.out.println(">>> Lifecycle example started."); // Create new configuration. IgniteConfiguration cfg = new IgniteConfiguration(); LifecycleExampleBean bean = new LifecycleExampleBean(); // Provide lifecycle bean to configuration. cfg.setLifecycleBeans(bean); try (Ignite ignite = Ignition.start(cfg)) { // Make sure that lifecycle bean was notified about ignite startup. assert bean.isStarted(); } // Make sure that lifecycle bean was notified about ignite stop. assert !bean.isStarted(); }
94. IgniteTxCachePrimarySyncTest#waitKeyUpdated()
Project: ignite
File: IgniteTxCachePrimarySyncTest.java
File: IgniteTxCachePrimarySyncTest.java
/** * @param ignite Node. * @param expNodes Expected number of cache server nodes. * @param cacheName Cache name. * @param key Cache key. * @throws Exception If failed. */ private void waitKeyUpdated(Ignite ignite, int expNodes, final String cacheName, final Object key) throws Exception { Affinity<Object> aff = ignite.affinity(cacheName); final Collection<ClusterNode> nodes = aff.mapKeyToPrimaryAndBackups(key); assertEquals(expNodes, nodes.size()); boolean wait = GridTestUtils.waitForCondition(new GridAbsPredicate() { @Override public boolean apply() { for (ClusterNode node : nodes) { Ignite ignite = grid(node); if (!key.equals(ignite.cache(cacheName).get(key))) return false; } return true; } }, 5000); assertTrue(wait); for (Ignite ignite0 : G.allGrids()) assertEquals(key, ignite0.cache(cacheName).get(key)); }
95. IgniteTxCachePrimarySyncTest#testTxSyncMode()
Project: ignite
File: IgniteTxCachePrimarySyncTest.java
File: IgniteTxCachePrimarySyncTest.java
/** * @throws Exception If failed. */ public void testTxSyncMode() throws Exception { Ignite ignite = ignite(0); List<IgniteCache<Object, Object>> caches = new ArrayList<>(); try { caches.add(createCache(ignite, cacheConfiguration("fullSync1", FULL_SYNC, 1, false, false), true)); caches.add(createCache(ignite, cacheConfiguration("fullSync2", FULL_SYNC, 1, false, false), true)); caches.add(createCache(ignite, cacheConfiguration("fullAsync1", FULL_ASYNC, 1, false, false), true)); caches.add(createCache(ignite, cacheConfiguration("fullAsync2", FULL_ASYNC, 1, false, false), true)); caches.add(createCache(ignite, cacheConfiguration("primarySync1", PRIMARY_SYNC, 1, false, false), true)); caches.add(createCache(ignite, cacheConfiguration("primarySync2", PRIMARY_SYNC, 1, false, false), true)); for (int i = 0; i < NODES; i++) { checkTxSyncMode(ignite(i), true); checkTxSyncMode(ignite(i), false); } } finally { for (IgniteCache<Object, Object> cache : caches) ignite.destroyCache(cache.getName()); } }
96. IgniteCachePrimarySyncTest#testPutGet()
Project: ignite
File: IgniteCachePrimarySyncTest.java
File: IgniteCachePrimarySyncTest.java
/** * @throws Exception If failed. */ public void testPutGet() throws Exception { Ignite ignite = ignite(SRVS); checkPutGet(ignite.cache("cache1"), null, null, null); checkPutGet(ignite.cache("cache2"), null, null, null); checkPutGet(ignite.cache("cache2"), ignite.transactions(), OPTIMISTIC, REPEATABLE_READ); checkPutGet(ignite.cache("cache2"), ignite.transactions(), OPTIMISTIC, SERIALIZABLE); checkPutGet(ignite.cache("cache2"), ignite.transactions(), PESSIMISTIC, READ_COMMITTED); }
97. IgniteCacheMessageRecoveryAbstractTest#closeSessions()
Project: ignite
File: IgniteCacheMessageRecoveryAbstractTest.java
File: IgniteCacheMessageRecoveryAbstractTest.java
/** * @throws Exception If failed. */ private boolean closeSessions() throws Exception { Ignite ignite = ignite(ThreadLocalRandom.current().nextInt(0, GRID_CNT)); log.info("Close sessions for: " + ignite.name()); TcpCommunicationSpi commSpi = (TcpCommunicationSpi) ignite.configuration().getCommunicationSpi(); Map<UUID, GridCommunicationClient> clients = U.field(commSpi, "clients"); boolean closed = false; for (GridCommunicationClient client : clients.values()) { GridTcpNioCommunicationClient client0 = (GridTcpNioCommunicationClient) client; GridNioSession ses = client0.session(); ses.close(); closed = true; } return closed; }
98. IgniteCacheManyClientsTest#checkNodes()
Project: ignite
File: IgniteCacheManyClientsTest.java
File: IgniteCacheManyClientsTest.java
/** * @param expCnt Expected number of nodes. */ private void checkNodes(int expCnt) { assertEquals(expCnt, G.allGrids().size()); long topVer = -1L; for (Ignite ignite : G.allGrids()) { log.info("Check node: " + ignite.name()); if (topVer == -1L) topVer = ignite.cluster().topologyVersion(); else assertEquals("Unexpected topology version for node: " + ignite.name(), topVer, ignite.cluster().topologyVersion()); assertEquals("Unexpected number of nodes for node: " + ignite.name(), expCnt, ignite.cluster().nodes().size()); } }
99. IgniteCache150ClientsTest#checkNodes()
Project: ignite
File: IgniteCache150ClientsTest.java
File: IgniteCache150ClientsTest.java
/** * @param expCnt Expected number of nodes. */ private void checkNodes(int expCnt) { assertEquals(expCnt, G.allGrids().size()); long topVer = -1L; for (Ignite ignite : G.allGrids()) { log.info("Check node: " + ignite.name()); if (topVer == -1L) topVer = ignite.cluster().topologyVersion(); else assertEquals("Unexpected topology version for node: " + ignite.name(), topVer, ignite.cluster().topologyVersion()); assertEquals("Unexpected number of nodes for node: " + ignite.name(), expCnt, ignite.cluster().nodes().size()); } }
100. GridCacheDhtPreloadStartStopSelfTest#checkKeys()
Project: ignite
File: GridCacheDhtPreloadStartStopSelfTest.java
File: GridCacheDhtPreloadStartStopSelfTest.java
/** * @param c Cache. * @param cnt Key count. */ private void checkKeys(IgniteCache<Integer, String> c, int cnt) { Affinity<Integer> aff = affinity(c); boolean sync = isSync(c); Ignite ignite = c.unwrap(Ignite.class); for (int i = 0; i < cnt; i++) { if (aff.mapPartitionToPrimaryAndBackups(aff.partition(i)).contains(ignite.cluster().localNode())) { String val = sync ? c.localPeek(i, CachePeekMode.ONHEAP) : c.get(i); assertEquals("Key check failed [grid=" + ignite.name() + ", cache=" + c.getName() + ", key=" + i + ']', Integer.toString(i), val); } } }