Java Code Examples for org.apache.ignite.IgniteCache#size()
The following examples show how to use
org.apache.ignite.IgniteCache#size() .
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: IgniteTestHelper.java From hibernate-ogm-ignite with GNU Lesser General Public License v2.1 | 6 votes |
@Override public long getNumberOfAssociations(SessionFactory sessionFactory, AssociationStorageType type) { int asscociationCount = 0; Set<IgniteCache<Object, BinaryObject>> processedCaches = Collections.newSetFromMap( new IdentityHashMap<IgniteCache<Object, BinaryObject>, Boolean>() ); for ( CollectionPersister collectionPersister : ( (SessionFactoryImplementor) sessionFactory ).getCollectionPersisters().values() ) { AssociationKeyMetadata associationKeyMetadata = ( (OgmCollectionPersister) collectionPersister ).getAssociationKeyMetadata(); IgniteCache<Object, BinaryObject> associationCache = getAssociationCache( sessionFactory, associationKeyMetadata ); if ( !processedCaches.contains( associationCache ) ) { asscociationCount += associationCache.size(); processedCaches.add( associationCache ); } } return asscociationCount; }
Example 2
Source File: PageEvictionReadThroughTest.java From ignite with Apache License 2.0 | 6 votes |
/** * @param atomicityMode Atomicity mode. * @param cacheMode Cache mode. * @throws Exception If failed. */ private void testEvictionWithReadThrough(CacheAtomicityMode atomicityMode, CacheMode cacheMode) throws Exception { startGrid(0); CacheConfiguration<Object, Object> cfg = cacheConfig("evict-rebalance", null, cacheMode, atomicityMode, CacheWriteSynchronizationMode.PRIMARY_SYNC); cfg.setReadThrough(true); cfg.setCacheStoreFactory(new TestStoreFactory()); IgniteCache<Object, Object> cache = ignite(0).getOrCreateCache(cfg); for (int i = 1; i <= ENTRIES; i++) { cache.get(i); if (i % (ENTRIES / 10) == 0) System.out.println(">>> Entries: " + i); } int size = cache.size(CachePeekMode.PRIMARY); System.out.println(">>> Resulting size: " + size); assertTrue(size > 0); assertTrue(size < ENTRIES); }
Example 3
Source File: GridCacheAbstractFullApiSelfTest.java From ignite with Apache License 2.0 | 6 votes |
/** * Checks iterators are cleared. */ private void waitForIteratorsCleared(IgniteCache<String, Integer> cache, int secs) throws InterruptedException { for (int i = 0; i < secs; i++) { try { cache.size(); // Trigger weak queue poll. checkIteratorsCleared(); } catch (Throwable t) { // If AssertionError is in the chain, assume we need to wait and retry. if (!X.hasCause(t, AssertionError.class)) throw t; if (i == 9) { for (int j = 0; j < gridCount(); j++) executeOnLocalOrRemoteJvm(j, new PrintIteratorStateTask()); throw t; } log.info("Iterators not cleared, will wait"); Thread.sleep(1000); } } }
Example 4
Source File: IgniteTestHelper.java From hibernate-ogm-ignite with GNU Lesser General Public License v2.1 | 5 votes |
@Override public long getNumberOfEntities(SessionFactory sessionFactory) { int entityCount = 0; Set<IgniteCache<?, ?>> processedCaches = Collections.newSetFromMap( new IdentityHashMap<IgniteCache<?, ?>, Boolean>() ); for ( EntityPersister entityPersister : ( (SessionFactoryImplementor) sessionFactory ).getEntityPersisters().values() ) { IgniteCache<?, ?> entityCache = getEntityCache( sessionFactory, ( (OgmEntityPersister) entityPersister ).getEntityKeyMetadata() ); if ( !processedCaches.contains( entityCache ) ) { entityCount += entityCache.size( CachePeekMode.ALL ); processedCaches.add( entityCache ); } } return entityCount; }
Example 5
Source File: CacheMvccSizeTest.java From ignite with Apache License 2.0 | 5 votes |
/** */ private void checkSizeModificationByOperation(Consumer<IgniteCache<?, ?>> beforeTx, Consumer<IgniteCache<?, ?>> inTx, boolean commit, int expSizeDelta) throws Exception { IgniteCache<Object, Object> tbl0 = grid(0).cache("person"); tbl0.query(q("delete from person")); beforeTx.accept(tbl0); int initSize = tbl0.size(); tbl0.query(q("begin")); inTx.accept(tbl0); // size is not changed before commit assertEquals(0, tbl0.size() - initSize); if (commit) tbl0.query(q("commit")); else tbl0.query(q("rollback")); assertEquals(expSizeDelta, tbl0.size() - initSize); assertEquals(tbl0.size(), table(grid(1)).size()); assertEquals(tbl0.size(), tbl0.size(BACKUP)); assertEquals(tbl0.size(), table(grid(1)).size(BACKUP)); }
Example 6
Source File: IgnitePdsCacheWalDisabledOnRebalancingTest.java From ignite with Apache License 2.0 | 5 votes |
/** */ private void verifyCache(IgniteCache cache, BiFunction<String, Integer, String> generatingFunc) { int size = cache.size(CachePeekMode.PRIMARY); String cacheName = cache.getName(); for (int i = 0; i < size; i++) { String value = (String) cache.get(i); assertEquals(generatingFunc.apply(cacheName, i), value); } }
Example 7
Source File: IgnitePdsCacheDestroyDuringCheckpointTest.java From ignite with Apache License 2.0 | 5 votes |
/** */ private void checkCacheSizes(Ignite client) { for (int i = 0; i < NUM_CACHES; i++) { IgniteCache<Object, Object> cache = client.getOrCreateCache(NAME_PREFIX + i); int size = cache.size(CachePeekMode.ALL); if (NUM_ENTRIES_PER_CACHE != size) { for (Object o : cache) { log.info("O " + o); } assertTrue(false); } } }
Example 8
Source File: PageEvictionMultinodeAbstractTest.java From ignite with Apache License 2.0 | 5 votes |
/** * @param cfg Config. * @throws Exception If failed. */ protected void createCacheAndTestEviction(CacheConfiguration<Object, Object> cfg) throws Exception { IgniteCache<Object, Object> cache = clientGrid().getOrCreateCache(cfg); for (int i = 1; i <= ENTRIES; i++) { ThreadLocalRandom r = ThreadLocalRandom.current(); if (r.nextInt() % 5 == 0) cache.put(i, new TestObject(PAGE_SIZE / 4 - 50 + r.nextInt(5000))); // Fragmented object. else cache.put(i, new TestObject(r.nextInt(PAGE_SIZE / 4 - 50))); // Fits in one page. if (r.nextInt() % 7 == 0) cache.get(r.nextInt(i)); // Touch. else if (r.nextInt() % 11 == 0) cache.remove(r.nextInt(i)); // Remove. else if (r.nextInt() % 13 == 0) cache.put(r.nextInt(i), new TestObject(r.nextInt(PAGE_SIZE / 2))); // Update. if (i % (ENTRIES / 10) == 0) System.out.println(">>> Entries put: " + i); } int resultingSize = cache.size(CachePeekMode.PRIMARY); System.out.println(">>> Resulting size: " + resultingSize); // Eviction started, no OutOfMemory occurred, success. assertTrue(resultingSize < ENTRIES * 10 / 11); clientGrid().destroyCache(cfg.getName()); }
Example 9
Source File: PageEvictionDataStreamerTest.java From ignite with Apache License 2.0 | 5 votes |
/** {@inheritDoc} */ @Override protected void createCacheAndTestEviction(CacheConfiguration<Object, Object> cfg) throws Exception { IgniteCache<Object, Object> cache = clientGrid().getOrCreateCache(cfg); try (IgniteDataStreamer<Object, Object> ldr = clientGrid().dataStreamer(cfg.getName())) { ldr.allowOverwrite(true); for (int i = 1; i <= ENTRIES; i++) { ThreadLocalRandom r = ThreadLocalRandom.current(); if (r.nextInt() % 5 == 0) ldr.addData(i, new TestObject(PAGE_SIZE / 4 - 50 + r.nextInt(5000))); // Fragmented object. else ldr.addData(i, new TestObject(r.nextInt(PAGE_SIZE / 4 - 50))); // Fits in one page. if (i % (ENTRIES / 10) == 0) System.out.println(">>> Entries put: " + i); } } int resultingSize = cache.size(CachePeekMode.PRIMARY); System.out.println(">>> Resulting size: " + resultingSize); // Eviction started, no OutOfMemory occurred, success. assertTrue(resultingSize < ENTRIES); clientGrid().destroyCache(cfg.getName()); }
Example 10
Source File: BinaryMetadataUpdatesFlowTest.java From ignite with Apache License 2.0 | 4 votes |
/** * @throws Exception If failed. */ @Test public void testFlowNoConflicts() throws Exception { startGridsMultiThreaded(GRID_CNT); doTestFlowNoConflicts(); awaitPartitionMapExchange(); Ignite randomNode = G.allGrids().get(0); IgniteCache<Object, Object> cache = randomNode.cache(DEFAULT_CACHE_NAME); int cacheEntries = cache.size(CachePeekMode.PRIMARY); assertTrue("Cache cannot contain more entries than were put in it;", cacheEntries <= UPDATES_COUNT); assertEquals("There are less than expected entries, data loss occurred;", UPDATES_COUNT, cacheEntries); validateCache(randomNode); }
Example 11
Source File: IgniteCacheExpireWhileRebalanceTest.java From ignite with Apache License 2.0 | 3 votes |
/** * @throws Exception If failed. */ @Test public void testExpireWhileRebalancing() throws Exception { startGridsMultiThreaded(CLUSTER_SIZE); IgniteCache<Object, Object> cache = ignite(0).cache(DEFAULT_CACHE_NAME); CountDownLatch latch = new CountDownLatch(1); new Thread(() -> { for (int i = 1; i <= ENTRIES; i++) { cache.put(i, i); if (i % (ENTRIES / 10) == 0) System.out.println(">>> Entries put: " + i); } latch.countDown(); }).start(); stopGrid(CLUSTER_SIZE - 1); awaitPartitionMapExchange(); startGrid(CLUSTER_SIZE - 1); latch.await(10, TimeUnit.SECONDS); int resultingSize = cache.size(CachePeekMode.PRIMARY); System.out.println(">>> Resulting size: " + resultingSize); assertTrue(resultingSize > 0); // Eviction started assertTrue(resultingSize < ENTRIES * 10 / 11); }
Example 12
Source File: IgnitePersistentStoreTest.java From ignite with Apache License 2.0 | 2 votes |
/** */ @Test public void loadCacheTest() { Ignition.stopAll(true); LOGGER.info("Running loadCache test"); LOGGER.info("Filling Cassandra table with test data"); CacheStore store = CacheStoreHelper.createCacheStore("personTypes", new ClassPathResource("org/apache/ignite/tests/persistence/pojo/persistence-settings-3.xml"), CassandraHelper.getAdminDataSrc()); Collection<CacheEntryImpl<PersonId, Person>> entries = TestsHelper.generatePersonIdsPersonsEntries(); //noinspection unchecked store.writeAll(entries); LOGGER.info("Cassandra table filled with test data"); LOGGER.info("Running loadCache test"); try (Ignite ignite = Ignition.start("org/apache/ignite/tests/persistence/pojo/ignite-config.xml")) { CacheConfiguration<PersonId, Person> ccfg = new CacheConfiguration<>("cache3"); IgniteCache<PersonId, Person> personCache3 = ignite.getOrCreateCache(ccfg); int size = personCache3.size(CachePeekMode.ALL); LOGGER.info("Initial cache size " + size); LOGGER.info("Loading cache data from Cassandra table"); String qry = "select * from test1.pojo_test3 limit 3"; personCache3.loadCache(null, qry); size = personCache3.size(CachePeekMode.ALL); Assert.assertEquals("Cache data was incorrectly loaded from Cassandra table by '" + qry + "'", 3, size); personCache3.clear(); personCache3.loadCache(null, new SimpleStatement(qry)); size = personCache3.size(CachePeekMode.ALL); Assert.assertEquals("Cache data was incorrectly loaded from Cassandra table by statement", 3, size); personCache3.clear(); personCache3.loadCache(null); size = personCache3.size(CachePeekMode.ALL); Assert.assertEquals("Cache data was incorrectly loaded from Cassandra. " + "Expected number of records is " + TestsHelper.getBulkOperationSize() + ", but loaded number of records is " + size, TestsHelper.getBulkOperationSize(), size); LOGGER.info("Cache data loaded from Cassandra table"); } LOGGER.info("loadCache test passed"); }
Example 13
Source File: PageEvictionWithRebalanceAbstractTest.java From ignite with Apache License 2.0 | 2 votes |
/** * @throws Exception If failed. */ public void checkEvictionWithRebalance(CacheAtomicityMode atomicityMode) throws Exception { startGridsMultiThreaded(4); CacheConfiguration<Object, Object> cfg = cacheConfig("evict-rebalance", null, CacheMode.PARTITIONED, atomicityMode, CacheWriteSynchronizationMode.PRIMARY_SYNC); IgniteCache<Object, Object> cache = ignite(0).getOrCreateCache(cfg); for (int i = 1; i <= ENTRIES; i++) { ThreadLocalRandom r = ThreadLocalRandom.current(); if (r.nextInt() % 5 == 0) cache.put(i, new TestObject(PAGE_SIZE / 4 - 50 + r.nextInt(5000))); // Fragmented object. else cache.put(i, new TestObject(r.nextInt(PAGE_SIZE / 4 - 50))); // Fits in one page. if (i % (ENTRIES / 10) == 0) System.out.println(">>> Entries put: " + i); } int size = cache.size(CachePeekMode.ALL); System.out.println(">>> Resulting size: " + size); assertTrue(size < ENTRIES * 2); // Primary entries and backups. for (int i = 3; i >= 1; i--) { stopGrid(i); cache.rebalance().get(); awaitPartitionMapExchange(); int rebalanceSize = cache.size(CachePeekMode.ALL); System.out.println(">>> Size after rebalance: " + rebalanceSize); assertTrue(rebalanceSize < size); size = rebalanceSize; } }