@Override public void append(final long key, final ByteBuffer payLoad) throws TimeoutException { performWaitingForHashInvalidation(key, () -> { delegate.append(key, payLoad); return null; }, entity.getTimeouts().getWriteOperationTimeout()); }
@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 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 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 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); }
@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)); }
@Override public void append(final long key, final ByteBuffer payLoad) throws TimeoutException { performWaitingForHashInvalidation(key, () -> { delegate.append(key, payLoad); return null; }, entity.getTimeouts().getWriteOperationTimeout()); }