/**
*
*/
@Test
public void testAlloc() throws Exception {
final RefAllocationsListener listener = hasServer ? null : getRefAllocationListener(cache.getRefAllocator());
Object res;
Op alloc;
Transaction txn = cache.beginTransaction();
alloc = new Op(ALLOC, -1L, 10, txn);
res = cache.runOp(alloc);
assertThat(res, is(PENDING));
if (hasServer)
verify(comm).send(argThat(equalTo(Message.ALLOC_REF(Comm.SERVER, DEFAULT_ALLOC_COUNT))));
else
verify(cluster).allocateRefs(anyInt());
if (hasServer)
cache.receive(Message.ALLOCED_REF(Message.ALLOC_REF(Comm.SERVER, DEFAULT_ALLOC_COUNT), 100, 3));
else
listener.refsAllocated(100, 3);
assertThat(alloc.getFuture().isDone(), is(false));
if (hasServer)
cache.receive(Message.ALLOCED_REF(Message.ALLOC_REF(Comm.SERVER, DEFAULT_ALLOC_COUNT), 200, 30));
else
listener.refsAllocated(200, 30);
res = alloc.getResult();
assertThat((Long) res, is(200L));
for (int i = 0; i < 10; i++) {
res = get(200L + i);
assertThat(res, is(nullValue()));
assertModified(200L + i, true);
assertThat(cache.getLine(200L + i).isLocked(), is(true));
}
res = doOp(ALLOC, -1L, 7, txn);
assertThat((Long) res, is(210L));
alloc = new Op(ALLOC, -1L, 20, txn);
res = cache.runOp(alloc);
assertThat(res, is(PENDING));
if (hasServer)
verify(comm, atLeastOnce()).send(argThat(equalTo(Message.ALLOC_REF(Comm.SERVER, DEFAULT_ALLOC_COUNT))));
else
verify(cluster, atLeastOnce()).allocateRefs(anyInt());
if (hasServer)
cache.receive(Message.ALLOCED_REF(Message.ALLOC_REF(Comm.SERVER, DEFAULT_ALLOC_COUNT), 300, 10));
else
listener.refsAllocated(300, 10);
assertThat(alloc.getFuture().isDone(), is(false));
if (hasServer)
cache.receive(Message.ALLOCED_REF(Message.ALLOC_REF(Comm.SERVER, DEFAULT_ALLOC_COUNT), 400, 50));
else
listener.refsAllocated(400, 50);
res = alloc.getResult();
assertThat((Long) res, is(400L));
}