assertEquals("1", cache.get(1)); assertTrue(cache.replace(1, "1", "3")); assertEquals("3", cache.get(1)); assertNull(cache.get(101)); assertTrue(cache.replace(100, "101")); assertEquals("101", cache.get(100)); assertNull(cache.get(100)); assertEquals("99", cache.get(99)); assertTrue(cache.remove(99, "99")); assertNull(cache.get(99)); assertEquals("101", cache.get(101));
String cachedVal = cache.get(key);
Person cachedVal = cache.get(key);
/** * 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); } } }
/** * 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")); } } }
/** * 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); } } }