public void testAdd() throws Exception {
StorageMemory storeSender = new StorageMemory();
StorageMemory storeRecv = new StorageMemory();
PeerDHT sender = null;
PeerDHT recv1 = null;
ChannelCreator cc = null;
try {
sender = new PeerBuilderDHT(new PeerBuilder(new Number160("0x50")).p2pId(55).ports(2424).start()).storage(storeSender).start();
recv1 = new PeerBuilderDHT(new PeerBuilder(new Number160("0x20")).p2pId(55).ports(8088).start()).storage(storeRecv).start();
StorageRPC smmSender = sender.storeRPC();
FutureChannelCreator fcc = recv1.peer().connectionBean().reservation().create(0, 1);
fcc.awaitUninterruptibly();
cc = fcc.channelCreator();
Collection<Data> dataSet = new HashSet<Data>();
dataSet.add(new Data(1));
AddBuilder addBuilder = new AddBuilder(recv1, new Number160(33));
addBuilder.domainKey(Number160.createHash("test"));
addBuilder.dataSet(dataSet);
addBuilder.versionKey(Number160.ZERO);
// addBuilder.setList();
// addBuilder.random(new Random(42));
FutureResponse fr = smmSender.add(recv1.peerAddress(), addBuilder, cc);
fr.awaitUninterruptibly();
System.err.println(fr.failedReason());
Assert.assertEquals(true, fr.isSuccess());
// add a the same data twice
fr = smmSender.add(recv1.peerAddress(), addBuilder, cc);
fr.awaitUninterruptibly();
System.err.println(fr.failedReason());
Assert.assertEquals(true, fr.isSuccess());
Number320 key = new Number320(new Number160(33), Number160.createHash("test"));
// Set<Number480> tofetch = new HashSet<Number480>();
Number640 from = new Number640(key, Number160.ZERO, Number160.ZERO);
Number640 to = new Number640(key, Number160.MAX_VALUE, Number160.MAX_VALUE);
SortedMap<Number640, Data> c = storeRecv.subMap(from, to, -1, true);
Assert.assertEquals(1, c.size());
for (Data data : c.values()) {
Assert.assertEquals((Integer) 1, (Integer) data.object());
}
// now add again, but as a list
addBuilder.list();
addBuilder.random(new Random(42));
fr = smmSender.add(recv1.peerAddress(), addBuilder, cc);
fr.awaitUninterruptibly();
System.err.println(fr.failedReason());
Assert.assertEquals(true, fr.isSuccess());
key = new Number320(new Number160(33), Number160.createHash("test"));
// Set<Number480> tofetch = new HashSet<Number480>();
from = new Number640(key, Number160.ZERO, Number160.ZERO);
to = new Number640(key, Number160.MAX_VALUE, Number160.MAX_VALUE);
c = storeRecv.subMap(from, to, -1, true);
Assert.assertEquals(2, c.size());
for (Data data : c.values()) {
Assert.assertEquals((Integer) 1, (Integer) data.object());
}
} finally {
if (cc != null) {
cc.shutdown().awaitListenersUninterruptibly();
}
if (sender != null) {
sender.shutdown().await();
}
if (recv1 != null) {