public EventualServerStoreProxy(String cacheId, final ClusterTierClientEntity entity, final ServerCallback invalidation) { this.delegate = new CommonServerStoreProxy(cacheId, entity, invalidation); }
public StrongServerStoreProxy(final String cacheId, final ClusterTierClientEntity entity, final ServerCallback invalidation) { this.delegate = new CommonServerStoreProxy(cacheId, entity, invalidation); this.entity = entity; delegate.addResponseListener(EhcacheEntityResponse.HashInvalidationDone.class, this::hashInvalidationDoneResponseListener); delegate.addResponseListener(EhcacheEntityResponse.AllInvalidationDone.class, this::allInvalidationDoneResponseListener); entity.addReconnectListener(this::reconnectListener); entity.addDisconnectionListener(this::disconnectionListener); }
@Test public void testGetKeyNotPresent() throws Exception { ClusterTierClientEntity clientEntity = createClientEntity("testGetKeyNotPresent"); CommonServerStoreProxy serverStoreProxy = new CommonServerStoreProxy("testGetKeyNotPresent", clientEntity, mock(ServerCallback.class)); Chain chain = serverStoreProxy.get(1); assertThat(chain.isEmpty(), is(true)); }
@Test public void testResolveRequestIsProcessedAtThreshold() throws Exception { ByteBuffer buffer = createPayload(42L); ClusterTierClientEntity clientEntity = createClientEntity("testResolveRequestIsProcessed"); ServerCallback serverCallback = mock(ServerCallback.class); when(serverCallback.compact(any(Chain.class), any(long.class))).thenReturn(getChain(false, buffer.duplicate())); CommonServerStoreProxy serverStoreProxy = new CommonServerStoreProxy("testResolveRequestIsProcessed", clientEntity, serverCallback); for (int i = 0; i < 8; i++) { serverStoreProxy.append(1L, buffer.duplicate()); } verify(serverCallback, never()).compact(any(Chain.class)); assertChainHas(serverStoreProxy.get(1L), 42L, 42L, 42L, 42L, 42L, 42L, 42L, 42L); //trigger compaction at > 8 entries serverStoreProxy.append(1L, buffer.duplicate()); verify(serverCallback).compact(any(Chain.class), any(long.class)); assertChainHas(serverStoreProxy.get(1L), 42L); }
@Test public void testAppendKeyNotPresent() throws Exception { ClusterTierClientEntity clientEntity = createClientEntity("testAppendKeyNotPresent"); CommonServerStoreProxy serverStoreProxy = new CommonServerStoreProxy("testAppendKeyNotPresent", clientEntity, mock(ServerCallback.class)); serverStoreProxy.append(2, createPayload(2)); Chain chain = serverStoreProxy.get(2); assertThat(chain.isEmpty(), is(false)); assertThat(readPayLoad(chain.iterator().next().getPayload()), is(2L)); }
@Test public void testClear() throws Exception { ClusterTierClientEntity clientEntity = createClientEntity("testClear"); CommonServerStoreProxy serverStoreProxy = new CommonServerStoreProxy("testClear", clientEntity, mock(ServerCallback.class)); serverStoreProxy.append(1L, createPayload(100L)); serverStoreProxy.clear(); Chain chain = serverStoreProxy.get(1); assertThat(chain.isEmpty(), is(true)); }
@Test public void testGetAndAppendKeyNotPresent() throws Exception { ClusterTierClientEntity clientEntity = createClientEntity("testGetAndAppendKeyNotPresent"); CommonServerStoreProxy serverStoreProxy = new CommonServerStoreProxy("testGetAndAppendKeyNotPresent", clientEntity, mock(ServerCallback.class)); Chain chain = serverStoreProxy.getAndAppend(4L, createPayload(4L)); assertThat(chain.isEmpty(), is(true)); chain = serverStoreProxy.get(4L); assertThat(chain.isEmpty(), is(false)); assertChainHas(chain, 4L); }
@Test public void testGetAfterMultipleAppendsOnSameKey() throws Exception { ClusterTierClientEntity clientEntity = createClientEntity("testGetAfterMultipleAppendsOnSameKey"); CommonServerStoreProxy serverStoreProxy = new CommonServerStoreProxy("testGetAfterMultipleAppendsOnSameKey", clientEntity, mock(ServerCallback.class)); serverStoreProxy.append(3L, createPayload(3L)); serverStoreProxy.append(3L, createPayload(33L)); serverStoreProxy.append(3L, createPayload(333L)); Chain chain = serverStoreProxy.get(3L); assertThat(chain.isEmpty(), is(false)); assertChainHas(chain, 3L, 33L, 333l); }
@Test public void testGetAndAppendMultipleTimesOnSameKey() throws Exception { ClusterTierClientEntity clientEntity = createClientEntity("testGetAndAppendMultipleTimesOnSameKey"); CommonServerStoreProxy serverStoreProxy = new CommonServerStoreProxy("testGetAndAppendMultipleTimesOnSameKey", clientEntity, mock(ServerCallback.class)); serverStoreProxy.getAndAppend(5L, createPayload(5L)); serverStoreProxy.getAndAppend(5L, createPayload(55L)); serverStoreProxy.getAndAppend(5L, createPayload(555L)); Chain chain = serverStoreProxy.getAndAppend(5l, createPayload(5555L)); assertThat(chain.isEmpty(), is(false)); assertChainHas(chain, 5L, 55L, 555L); }
@Before public void setup() throws Exception { UnitTestConnectionService.add( CLUSTER_URI, new UnitTestConnectionService.PassthroughServerBuilder().resource("defaultResource", 8, MemoryUnit.MB).build() ); Connection connection = new UnitTestConnectionService().connect(CLUSTER_URI, new Properties()); ClusterTierManagerClientEntityFactory entityFactory = new ClusterTierManagerClientEntityFactory(connection); ServerSideConfiguration serverConfig = new ServerSideConfiguration("defaultResource", Collections.emptyMap()); entityFactory.create("TestCacheManager", serverConfig); ClusteredResourcePool resourcePool = ClusteredResourcePoolBuilder.clusteredDedicated(4, MemoryUnit.MB); ServerStoreConfiguration serverStoreConfiguration = new ServerStoreConfiguration(resourcePool.getPoolAllocation(), Long.class.getName(), String.class.getName(), LongSerializer.class.getName(), StringSerializer.class.getName(), null, false); ClusterTierClientEntity clientEntity = entityFactory.fetchOrCreateClusteredStoreEntity("TestCacheManager", CACHE_IDENTIFIER, serverStoreConfiguration, true); clientEntity.validate(serverStoreConfiguration); ServerStoreProxy serverStoreProxy = new CommonServerStoreProxy(CACHE_IDENTIFIER, clientEntity, mock(ServerCallback.class)); TestTimeSource testTimeSource = new TestTimeSource(); OperationsCodec<Long, String> codec = new OperationsCodec<>(new LongSerializer(), new StringSerializer()); EternalChainResolver<Long, String> resolver = new EternalChainResolver<>(codec); store = new ClusteredStore<>(config, codec, resolver, serverStoreProxy, testTimeSource); }
@Test public void testReplaceAtHeadSuccessFull() throws Exception { ClusterTierClientEntity clientEntity = createClientEntity("testReplaceAtHeadSuccessFull"); CommonServerStoreProxy serverStoreProxy = new CommonServerStoreProxy("testReplaceAtHeadSuccessFull", clientEntity, mock(ServerCallback.class)); serverStoreProxy.append(20L, createPayload(200L)); serverStoreProxy.append(20L, createPayload(2000L)); serverStoreProxy.append(20L, createPayload(20000L)); Chain expect = serverStoreProxy.get(20L); Chain update = getChain(false, createPayload(400L)); serverStoreProxy.replaceAtHead(20l, expect, update); Chain afterReplace = serverStoreProxy.get(20L); assertChainHas(afterReplace, 400L); serverStoreProxy.append(20L, createPayload(4000L)); serverStoreProxy.append(20L, createPayload(40000L)); serverStoreProxy.replaceAtHead(20L, afterReplace, getChain(false, createPayload(800L))); Chain anotherReplace = serverStoreProxy.get(20L); assertChainHas(anotherReplace, 800L, 4000L, 40000L); }
public EventualServerStoreProxy(String cacheId, final ClusterTierClientEntity entity, final ServerCallback invalidation) { this.delegate = new CommonServerStoreProxy(cacheId, entity, invalidation); }
public StrongServerStoreProxy(final String cacheId, final ClusterTierClientEntity entity, final ServerCallback invalidation) { this.delegate = new CommonServerStoreProxy(cacheId, entity, invalidation); this.entity = entity; delegate.addResponseListener(EhcacheEntityResponse.HashInvalidationDone.class, this::hashInvalidationDoneResponseListener); delegate.addResponseListener(EhcacheEntityResponse.AllInvalidationDone.class, this::allInvalidationDoneResponseListener); entity.setReconnectListener(this::reconnectListener); entity.addDisconnectionListener(this::disconnectionListener); }