private void internalPut(String hashedKey, byte[] encodedValue, int expiration) { try { client.set(hashedKey, expiration, encodedValue); putCount.incrementAndGet(); putBytes.addAndGet(encodedValue.length); } catch (IllegalStateException e) { // operation did not get queued in time (queue is full) errorCount.incrementAndGet(); logger.error(UNABLE_TO_QUEUE_CACHE_OPERATION, e); } catch (Throwable t) { errorCount.incrementAndGet(); logger.error(UNABLE_TO_QUEUE_CACHE_OPERATION, t); } }
/** * @param keyS should be the serialized string */ public void evict(String keyS) { if (keyS == null) return; client.delete(computeKeyHash(keyS)); }
/** * @throws Exception If failed. */ @Test public void testGet() throws Exception { jcache().put("getKey1", "getVal1"); jcache().put("getKey2", "getVal2"); Assert.assertEquals("getVal1", client.get("getKey1")); Assert.assertEquals("getVal2", client.get("getKey2")); Assert.assertNull(client.get("wrongKey")); }
bulkFuture = client.asyncGetBulk(keyLookup.keySet()); } catch (IllegalStateException e) { client.delete(partitalKey);
/** * @throws Exception If failed. */ @Test public void testSpecialTypes() throws Exception { Assert.assertTrue(client.set("boolKey", 0, true).get()); Assert.assertEquals(true, client.get("boolKey")); Assert.assertTrue(client.set("intKey", 0, 10).get()); Assert.assertEquals(10, client.get("intKey")); Assert.assertTrue(client.set("longKey", 0, 100L).get()); Assert.assertEquals(100L, client.get("longKey")); Date now = new Date(); Assert.assertTrue(client.set("dateKey", 0, now).get()); Assert.assertEquals(now, client.get("dateKey")); Assert.assertTrue(client.set("byteKey", 0, (byte) 1).get()); Assert.assertEquals((byte) 1, client.get("byteKey")); Assert.assertTrue(client.set("floatKey", 0, 1.1).get()); Assert.assertEquals(1.1, client.get("floatKey")); Assert.assertTrue(client.set("doubleKey", 0, 100.001d).get()); Assert.assertEquals(100.001d, client.get("doubleKey")); byte[] arr = new byte[5]; for (byte i = 0; i < arr.length; i++) arr[i] = i; Assert.assertTrue(client.set("arrKey", 0, arr).get()); assertArrayEquals(arr, (byte[])client.get("arrKey")); Assert.assertTrue(client.set("shortKey", 0, (short) 1).get()); Assert.assertEquals((short) 1, client.get("shortKey")); }
/** * @throws Exception If failed. */ @Test public void testAppend() throws Exception { Assert.assertFalse(client.append(0, "appendKey", "_suffix").get()); jcache().put("appendKey", "appendVal"); Assert.assertTrue(client.append(0, "appendKey", "_suffix").get()); Assert.assertEquals("appendVal_suffix", client.get("appendKey")); assertEquals("appendVal_suffix", jcache().get("appendKey")); }
/** * @throws Exception If failed. */ @Test 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(); }
/** * @throws Exception If failed. */ @Test public void testAdd() throws Exception { jcache().put("addKey1", "addVal1"); Assert.assertFalse(client.add("addKey1", 0, "addVal1New").get()); Assert.assertTrue(client.add("addKey2", 0, "addVal2").get()); assertEquals("addVal1", jcache().get("addKey1")); assertEquals("addVal2", jcache().get("addKey2")); }
/** * Construct a CacheMap over the given MemcachedClient. * * @param c the client * @param expiration the expiration to set for keys written to the cache * @param prefix a prefix used to make keys in this map unique */ public CacheMap(MemcachedClientIF c, int expiration, String prefix) { super(c, expiration, prefix, c.getTranscoder()); }
final ComposableFuture<CASValue<V>> getFutureValue = SpyFutureHelper.fromCASValue(() -> { @SuppressWarnings("unchecked") final Transcoder<V> transcoder = (Transcoder<V>) spyClient.getTranscoder(); return spyClient.asyncGets(cacheKey, transcoder); }); return SpyFutureHelper.fromCASResponse(() -> spyClient.asyncCAS(cacheKey, result.getCas(), newValue)); () -> spyClient.add(cacheKey, expirationSpyUnits, newValue));
_memcached.shutdown(); _daemon.stop(); assertNotNull( new SessionIdFormat().extractMemcachedId( sessionId1 ), "memcached node id missing with msm switched to enabled" ); Thread.sleep( 50 ); assertNotNull( _memcached.get( sessionId1 ), "Session not available in memcached." ); assertNull( _memcached.get( sessionId1 ), "Expired session still existing in memcached" );
long start = System.currentTimeMillis(); try { future = client.asyncGet(hashedKey); } catch (IllegalStateException e) {
@Override public ComposableFuture<V> getAsync(final K key) { return SpyFutureHelper.fromGet(() -> { @SuppressWarnings("unchecked") final Transcoder<V> transcoder = (Transcoder<V>) spyClient.getTranscoder(); return spyClient.asyncGet(keyTranslator.translateKey(key), transcoder); }); }
@Override protected void tearDown() { client.shutdown(1, TimeUnit.MINUTES); }
@Override public ComposableFuture<Map<K, V>> getBulkAsync(final Iterable<? extends K> keys) { final List<String> stringKeys = new ArrayList<>(); final Map<String, K> keysMap = new HashMap<>(); try { for (final K key : keys) { final String stringKey = keyTranslator.translateKey(key); stringKeys.add(stringKey); keysMap.put(stringKey, key); } return SpyFutureHelper.fromBulkGet(() -> { @SuppressWarnings("unchecked") final Transcoder<V> transcoder = (Transcoder<V>) spyClient.getTranscoder(); return spyClient.asyncGetBulk(stringKeys, transcoder); }, keysMap); } catch (final Exception e) { return fromError(e); } }
/** * @throws Exception If failed. */ @Test public void testAddWithExpiration() throws Exception { Assert.assertTrue(client.add("addKey", 2000, "addVal").get()); assertEquals("addVal", jcache().get("addKey")); Thread.sleep(2100); Assert.assertNull(jcache().get("addKey")); }