@Test public void testGetValue() throws Exception { ByteBuf returnedValue = Unpooled.copiedBuffer("test-value", UTF_8); when(mockTable.get(any(ByteBuf.class))) .thenReturn(FutureUtils.value(returnedValue)); ByteBuffer result = stateContext.get("test-key").get(); assertEquals("test-value", new String(result.array(), UTF_8)); verify(mockTable, times(1)).get( eq(Unpooled.copiedBuffer("test-key", UTF_8)) ); }
@Override public CompletableFuture<ByteBuffer> get(String key) { return table.get(Unpooled.wrappedBuffer(key.getBytes(UTF_8))).thenApply( data -> { try { if (data != null) { ByteBuffer result = ByteBuffer.allocate(data.readableBytes()); data.readBytes(result); result.position(0); return result; } return null; } finally { ReferenceCountUtil.safeRelease(data); } } ); }
StateContextImpl implements StateContext { @Override public CompletableFuture<ByteBuffer> get(String key) { return table.get(Unpooled.wrappedBuffer(key.getBytes(UTF_8))).thenApply( data -> { try { if (data != null) { ByteBuffer result = ByteBuffer.allocate(data.readableBytes()); data.readBytes(result); result.position(0); return result; } return null; } finally { ReferenceCountUtil.safeRelease(data); } } ); } }
StateContextImpl implements StateContext { @Override public CompletableFuture<ByteBuffer> get(String key) { return table.get(Unpooled.wrappedBuffer(key.getBytes(UTF_8))).thenApply( data -> { try { if (data != null) { ByteBuffer result = ByteBuffer.allocate(data.readableBytes()); data.readBytes(result); result.position(0); return result; } return null; } finally { ReferenceCountUtil.safeRelease(data); } } ); } StateContextImpl(Table<ByteBuf, ByteBuf> table); }
StateContextImpl implements StateContext { @Override public CompletableFuture<ByteBuffer> get(String key) { return table.get(Unpooled.wrappedBuffer(key.getBytes(UTF_8))).thenApply( data -> { try { if (data != null) { ByteBuffer result = ByteBuffer.allocate(data.readableBytes()); data.readBytes(result); result.position(0); return result; } return null; } finally { ReferenceCountUtil.safeRelease(data); } } ); } StateContextImpl(Table<ByteBuf, ByteBuf> table); @Override CompletableFuture<Void> incrCounter(String key, long amount); @Override CompletableFuture<Void> put(String key, ByteBuffer value); @Override CompletableFuture<Void> delete(String key); @Override CompletableFuture<ByteBuffer> get(String key); @Override CompletableFuture<Long> getCounter(String key); }
StateContextImpl implements StateContext { @Override public CompletableFuture<ByteBuffer> get(String key) { return table.get(Unpooled.wrappedBuffer(key.getBytes(UTF_8))).thenApply( data -> { try { if (data != null) { ByteBuffer result = ByteBuffer.allocate(data.readableBytes()); data.readBytes(result); result.position(0); return result; } return null; } finally { ReferenceCountUtil.safeRelease(data); } } ); } StateContextImpl(Table<ByteBuf, ByteBuf> table); @Override CompletableFuture<Void> incrCounter(String key, long amount); @Override CompletableFuture<Void> put(String key, ByteBuffer value); @Override CompletableFuture<Void> delete(String key); @Override CompletableFuture<ByteBuffer> get(String key); @Override CompletableFuture<Long> getCounter(String key);  }