OffHeapByteBuffer implements OffHeapStore { public Pointer update(final Pointer pointer, final byte[] payload, final long expiry) { readWriteLock.writeLock(pointer.getPosition()); try { final byte[] exPayload = retrieve(pointer); if (exPayload.length >= payload.length) { dirtyMemory.addAndGet(exPayload.length - payload.length); final Allocation allocation = new Allocation(pointer.getPosition(), payload.length + POINTER_SIZE); return store(allocation, payload, expiry); } else { dirtyMemory.addAndGet(exPayload.length + POINTER_SIZE); markAsDirty(pointer.getPosition()); return store(payload, expiry); } } finally { readWriteLock.writeUnlock(pointer.getPosition()); } } OffHeapByteBuffer(int index, int capacity);  OffHeapByteBuffer(int index, int capacity, int concurrencyLevel); byte[] retrieve(final Pointer pointer); byte[] remove(Pointer pointer); Pointer store(final byte[] payload, final long expiry); Pointer store(final Allocation allocation, byte[] payload, final long expiry); Pointer update(final Pointer pointer, final byte[] payload, final long expiry); void free(); long dirtyMemory(); long usedMemory(); long freeMemory(); int getIndex(); final static int DEFAULT_CONCURRENCY_LEVEL; }
@Test public void update() { int size = 100; final long expiry = System.currentTimeMillis(); byte[] bytes = new byte[size]; random.nextBytes(bytes); Pointer pointer = buffer.store(bytes, expiry); byte[] expectedBytes = new byte[size]; random.nextBytes(expectedBytes); pointer = buffer.update(pointer, expectedBytes, expiry); byte[] actualBytes = buffer.retrieve(pointer); assertArrayEquals(expectedBytes, actualBytes); }