/** * @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")); }
/** * @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 testComplexObject() throws Exception { Assert.assertTrue(client.set("objKey", 0, new ValueObject(10, "String")).get()); Assert.assertEquals(new ValueObject(10, "String"), client.get("objKey")); }
/** * @throws Exception If failed. */ @Test public void testPrepend() throws Exception { Assert.assertFalse(client.append(0, "prependKey", "_suffix").get()); jcache().put("prependKey", "prependVal"); Assert.assertTrue(client.append(0, "prependKey", "_suffix").get()); Assert.assertEquals("prependVal_suffix", client.get("prependKey")); assertEquals("prependVal_suffix", jcache().get("prependKey")); }
/** * @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(); }
@Override public byte[] get(final String key) { return _memcached.get(key, ByteArrayTranscoder.INSTANCE); } };
@Test( enabled = true, dataProviderClass = TestUtils.class, dataProvider = STICKYNESS_PROVIDER ) public void testSessionAvailableInMemcached( final SessionAffinityMode sessionAffinity ) throws IOException, InterruptedException, HttpException { setStickyness(sessionAffinity); final String sessionId1 = makeRequest( _httpClient, _portTomcat1, null ); assertNotNull( sessionId1, "No session created." ); Thread.sleep( 50 ); assertNotNull( _memcached.get( sessionId1 ), "Session not available in memcached." ); }
@Override public Object call() throws Exception { return _memcached.get(new SessionIdFormat().createValidityInfoKeyName(sessionId1)); } }, nullValue() );
@Test( enabled = true, dataProviderClass = TestUtils.class, dataProvider = STICKYNESS_PROVIDER ) public void testExpiredSessionRemovedFromMemcached( @Nonnull final SessionAffinityMode sessionAffinity ) throws IOException, InterruptedException, HttpException { setStickyness(sessionAffinity); final String sessionId1 = makeRequest( _httpClient, _portTomcat1, null ); assertNotNull( sessionId1, "No session created." ); waitForSessionExpiration( sessionAffinity.isSticky() ); assertNull( _memcached.get( sessionId1 ), "Expired session still existing in memcached" ); }
@Test( enabled = true, dataProviderClass = TestUtils.class, dataProvider = STICKYNESS_PROVIDER ) public void testInvalidatedSessionRemovedFromMemcached( @Nonnull final SessionAffinityMode sessionAffinity ) throws IOException, InterruptedException, HttpException { setStickyness(sessionAffinity); final String sessionId1 = makeRequest( _httpClient, _portTomcat1, null ); assertNotNull( sessionId1, "No session created." ); final Response response = get( _httpClient, _portTomcat1, PATH_INVALIDATE, sessionId1 ); assertNull( response.getResponseSessionId() ); assertNull( _memcached.get( sessionId1 ), "Invalidated session still existing in memcached" ); if(!sessionAffinity.isSticky()) { // Check that ValidityInfo for invalidated session does not exist in memcached await().until(new Callable<Object>() { @Override public Object call() throws Exception { return _memcached.get(new SessionIdFormat().createValidityInfoKeyName(sessionId1)); } }, nullValue() ); } }
@Test( enabled = true, dataProviderClass = TestUtils.class, dataProvider = STICKYNESS_PROVIDER ) public void testSessionAvailableInMemcachedWithCookiesDisabled( final SessionAffinityMode sessionAffinity ) throws Exception { _tomcat1.stop(); _tomcat1 = tcBuilder().sticky(sessionAffinity.isSticky()).cookies(false).jvmRoute("app1").buildAndStart(); final Response response = get(_httpClient, _portTomcat1, null); final String sessionId = response.get( TestServlet.ID ); assertNotNull( sessionId, "No session created." ); Thread.sleep( 50 ); assertNotNull( _memcached.get( sessionId ), "Session not available in memcached." ); }
assertWaitingWithProxy(Predicates.<MemcachedClientIF> notNull(), 200l, _memcached).get( sessionId1 ); assertNotNull( _memcached.get( sessionId1 ), "Session should still exist in memcached." ); assertNotNull( _memcached.get( sessionId1 ), "Session should still exist in memcached." ); assertNotNull( _memcached.get( sessionId1 ), "Session should still exist in memcached." );
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" );
public V get(Object key) { V rv = null; try { rv = client.get(getKey((String) key), transcoder); } catch (ClassCastException e) { // Most likely, this is because the key wasn't a String. // Either way, it's a no. } return rv; }
@Override public <T> T get(Object key, Class<T> type) { Assert.notNull(key, "key parameter is mandatory"); Assert.isAssignable(String.class, key.getClass()); Object result = this.memcachedClientIF.get((String) key); if (result == null) { return null; } Assert.isAssignable(type, result.getClass()); return type.cast(result); }
@Override public ValueWrapper get(Object key) { Assert.notNull(key, "key parameter is mandatory"); Assert.isAssignable(String.class, key.getClass()); Object result = this.memcachedClientIF.get((String) key); return result != null ? new SimpleValueWrapper(result) : null; }
@Override public Object get(final String key) throws TimeoutException, CacheException { try { return memcachedClient.get(key); } catch (RuntimeException e) { if (translateException(e)) { throw new CacheException(e); } else if (e.getCause() instanceof TimeoutException) { throw (TimeoutException) e.getCause(); } throw e; } }
public HttpCacheEntry getEntry(String url) throws IOException { String key = getCacheKey(url); if (key == null) return null; try { MemcachedCacheEntry mce = reconstituteEntry(client.get(key)); if (mce == null || !url.equals(mce.getStorageKey())) return null; return mce.getHttpCacheEntry(); } catch (OperationTimeoutException ex) { throw new MemcachedOperationTimeoutException(ex); } }