cache.putAll(data); assertFalse(cache.replace(1, "2", "3")); assertEquals("1", cache.get(1)); assertTrue(cache.replace(1, "1", "3")); assertEquals("3", cache.get(1)); assertFalse(cache.replace(101, "101")); assertNull(cache.get(101)); assertTrue(cache.replace(100, "101")); assertEquals("101", cache.get(100)); assertFalse(cache.remove(101)); assertTrue(cache.remove(100)); assertNull(cache.get(100)); assertFalse(cache.remove(99, "100")); assertEquals("99", cache.get(99)); assertTrue(cache.remove(99, "99")); assertNull(cache.get(99)); cache.put(101, "101"); cache.removeAll(data.keySet()); assertEquals(1, cache.size()); assertEquals("101", cache.get(101)); cache.removeAll(); assertEquals(0, cache.size());
/** * Put/get operations with Ignite Binary Object API */ @Test public void testBinaryObjectPutGet() throws Exception { int key = 1; try (Ignite ignored = Ignition.start(Config.getServerConfiguration())) { try (IgniteClient client = Ignition.startClient(new ClientConfiguration().setAddresses(Config.SERVER)) ) { IgniteBinary binary = client.binary(); BinaryObject val = binary.builder("Person") .setField("id", 1, int.class) .setField("name", "Joe", String.class) .build(); ClientCache<Integer, BinaryObject> cache = client.cache(Config.DEFAULT_CACHE_NAME).withKeepBinary(); cache.put(key, val); BinaryObject cachedVal = client.cache(Config.DEFAULT_CACHE_NAME).<Integer, BinaryObject>withKeepBinary().get(key); assertBinaryObjectsEqual(val, cachedVal); } } }
/** * Tested API: * <ul> * <li>{@link ClientCache#getAndPut(Object, Object)}</li> * <li>{@link ClientCache#getAndRemove(Object)}</li> * <li>{@link ClientCache#getAndReplace(Object, Object)}</li> * <li>{@link ClientCache#putIfAbsent(Object, Object)}</li> * </ul> */ @Test public void testAtomicPutGet() throws Exception { try (Ignite ignored = Ignition.start(Config.getServerConfiguration()); IgniteClient client = Ignition.startClient(getClientConfiguration()) ) { ClientCache<Integer, String> cache = client.createCache("testRemoveReplace"); assertNull(cache.getAndPut(1, "1")); assertEquals("1", cache.getAndPut(1, "1.1")); assertEquals("1.1", cache.getAndRemove(1)); assertNull(cache.getAndRemove(1)); assertTrue(cache.putIfAbsent(1, "1")); assertFalse(cache.putIfAbsent(1, "1.1")); assertEquals("1", cache.getAndReplace(1, "1.1")); assertEquals("1.1", cache.getAndReplace(1, "1")); assertNull(cache.getAndReplace(2, "2")); } }
.collect(Collectors.toMap(i -> i, i -> new Person(i, String.format("Person %s", i)))); cache.putAll(data); Map<Integer, Person> cachedData = cache.getAll(data.keySet()); .collect(Collectors.toMap(i -> new Person(i, String.format("Person %s", i)), i -> i)); cache.putAll(data); Map<Person, Integer> cachedData = cache.getAll(data.keySet()); cache.clear(); assertEquals(0, cache.size(CachePeekMode.ALL));
.setQueryEntities(qryPerson); ClientCache<Integer, BinaryObject> cache = client.getOrCreateCache(cacheCfg).withKeepBinary(); )); cache.putAll(data); .query(new SqlQuery<Integer, BinaryObject>(TYPE_NAME, "id = 1")) .getAll() .iterator()
cache.put(key, val); assertEquals(1, cache.size()); assertEquals(2, cache.size(CachePeekMode.ALL)); Person cachedVal = cache.get(key); assertFalse(cache.containsKey(key)); assertFalse(cache.containsKey(key));
/** * Reading schema-less Ignite Binary object. */ @Test public void testReadingSchemalessIgniteBinaries() throws Exception { int key = 1; Person val = new Person(key, "Joe"); try (Ignite srv = Ignition.start(Config.getServerConfiguration())) { // Add an entry directly to the Ignite server. This stores a schema-less object in the cache and // does not register schema in the client's metadata cache. srv.cache(Config.DEFAULT_CACHE_NAME).put(key, val); try (IgniteClient client = Ignition.startClient(new ClientConfiguration().setAddresses(Config.SERVER))) { ClientCache<Integer, BinaryObject> cache = client.cache(Config.DEFAULT_CACHE_NAME).withKeepBinary(); BinaryObject cachedVal = cache.get(key); assertEquals(val.getId(), cachedVal.field("id")); assertEquals(val.getName(), cachedVal.field("name")); } } }
/** * Unmarshalling schema-less Ignite binary objects into Java static types. */ @Test public void testUnmarshalSchemalessIgniteBinaries() throws Exception { int key = 1; Person val = new Person(key, "Joe"); try (Ignite srv = Ignition.start(Config.getServerConfiguration())) { // Add an entry directly to the Ignite server. This stores a schema-less object in the cache and // does not register schema in the client's metadata cache. srv.cache(Config.DEFAULT_CACHE_NAME).put(key, val); try (IgniteClient client = Ignition.startClient(new ClientConfiguration().setAddresses(Config.SERVER))) { ClientCache<Integer, Person> cache = client.cache(Config.DEFAULT_CACHE_NAME); Person cachedVal = cache.get(key); assertEquals(val, cachedVal); } } }
.collect(Collectors.toMap(i -> i, i -> new Person(i, String.format("Person %s", i)))); cache.putAll(data); try (QueryCursor<Cache.Entry<Integer, Person>> cur = cache.query(qry)) { List<Cache.Entry<Integer, Person>> res = cur.getAll(); .setPageSize(pageSize); try (QueryCursor<List<?>> cur = cache.query(qry)) { List<List<?>> res = cur.getAll();