public void testWriteGaps() throws Exception {
final Object notifyObject = new Object();
byte[] passwd = new byte[20];
Arrays.fill(passwd, (byte) 'a');
BookieClient bc = new BookieClient("127.0.0.1", port, 50000);
ByteBuffer bb;
bb = createByteBuffer(1,1,1);
bc.addEntry(1, passwd, 1, bb, wrcb, null);
bb = createByteBuffer(2,1,2);
bc.addEntry(1, passwd, 2, bb, wrcb, null);
bb = createByteBuffer(3,1,3);
bc.addEntry(1, passwd, 3, bb, wrcb, null);
bb = createByteBuffer(5,1,5);
bc.addEntry(1, passwd, 5, bb, wrcb, null);
bb = createByteBuffer(7,1,7);
bc.addEntry(1, passwd, 7, bb, wrcb, null);
synchronized(notifyObject) {
bb = createByteBuffer(11,1,11);
bc.addEntry(1, passwd, 11, bb, wrcb, notifyObject);
notifyObject.wait();
}
ResultStruct arc = new ResultStruct();
synchronized(arc) {
bc.readEntry(1, 6, recb, arc);
arc.wait(1000);
assertEquals(BookieProtocol.ENOENTRY, arc.rc);
}
synchronized(arc) {
bc.readEntry(1, 7, recb, arc);
arc.wait(1000);
assertEquals(0, arc.rc);
assertEquals(7, arc.entry.getInt());
}
synchronized(arc) {
bc.readEntry(1, 1, recb, arc);
arc.wait(1000);
assertEquals(0, arc.rc);
assertEquals(1, arc.entry.getInt());
}
synchronized(arc) {
bc.readEntry(1, 2, recb, arc);
arc.wait(1000);
assertEquals(0, arc.rc);
assertEquals(2, arc.entry.getInt());
}
synchronized(arc) {
bc.readEntry(1, 3, recb, arc);
arc.wait(1000);
assertEquals(0, arc.rc);
assertEquals(3, arc.entry.getInt());
}
synchronized(arc) {
bc.readEntry(1, 4, recb, arc);
arc.wait(1000);
assertEquals(BookieProtocol.ENOENTRY, arc.rc);
}
synchronized(arc) {
bc.readEntry(1, 11, recb, arc);
arc.wait(1000);
assertEquals(0, arc.rc);
assertEquals(11, arc.entry.getInt());
}
synchronized(arc) {
bc.readEntry(1, 5, recb, arc);
arc.wait(1000);
assertEquals(0, arc.rc);
assertEquals(5, arc.entry.getInt());
}
synchronized(arc) {
bc.readEntry(1, 10, recb, arc);
arc.wait(1000);
assertEquals(BookieProtocol.ENOENTRY, arc.rc);
}
synchronized(arc) {
bc.readEntry(1, 12, recb, arc);
arc.wait(1000);
assertEquals(BookieProtocol.ENOENTRY, arc.rc);
}
synchronized(arc) {
bc.readEntry(1, 13, recb, arc);
arc.wait(1000);
assertEquals(BookieProtocol.ENOENTRY, arc.rc);
}
}