@Override public long write(ByteBuffer buffer) { return other.write(buffer) ; }
@Override public long write(ByteBuffer buffer) { info("write"+buffer) ; return other.write(buffer) ; }
@Override public long write(ByteBuffer buffer) { checkWriteTxn(); return objFile.write(buffer) ; }
@Test public void objectfile_03() { ByteBuffer bb = ByteBuffer.allocate(10) ; fill(bb) ; long x1 = file.write(bb) ; assertEquals(0, x1) ; }
@Test public void objectfile_06() { ByteBuffer bb1 = ByteBuffer.allocate(10) ; fill(bb1) ; ByteBuffer bb2 = ByteBuffer.allocate(20) ; fill(bb2) ; long x1 = file.write(bb1) ; long x2 = file.write(bb2) ; ByteBuffer bb1a = file.read(x1) ; ByteBuffer bb2a = file.read(x2) ; assertNotSame(bb1a, bb2a) ; assertTrue(sameValue(bb1, bb1a)) ; assertTrue(sameValue(bb2, bb2a)) ; }
private void write(int sizeOfBuffer, int... sizes) { ObjectFile file = make(sizeOfBuffer) ; int N = sizes.length ; ByteBuffer bb[] = new ByteBuffer[N] ; long loc[] = new long[N] ; ByteBuffer read[] = new ByteBuffer[N] ; for ( int i = 0 ; i < N ; i++ ) { bb[i] = ByteBuffer.allocate(sizes[i]) ; fill(bb[i]) ; loc[i] = file.write(bb[i]) ; } //file.sync() ; for ( int i = 0 ; i < N ; i++ ) { read[i] = file.read(loc[i]) ; assertNotSame(bb[i], read[i]) ; sameValue(bb[i], read[i]) ; } }
@Test public void transObjectFile_4() { String str1 = "Test4" ; String str2 = "TheNext" ; long x1 = writeOne(transactional, transObjectFile, str1) ; ByteBuffer bb = str2bb(str2) ; long x2 = baseObjectFile.write(bb) ; baseObjectFile.sync(); long x3 = Txn.calculateRead(transactional, ()->transObjectFile.length()) ; assertEquals(x2, x3); assertNotEquals(x3, baseObjectFile.length()); // Fake recovery. ByteBuffer bbj = ByteBuffer.allocate(2*Long.BYTES) ; bbj.putLong(x3) ; bbj.putLong(0) ; bbj.rewind() ; journal.write(JournalEntryType.REDO, transObjectFile.getComponentId(), bbj) ; journal.writeJournal(JournalEntry.COMMIT) ; // Recovery. //transObjectFile.recover(bb); TransactionalBase transBase = (TransactionalBase)TransactionalFactory.createTransactional(journal, transObjectFile) ; ByteBuffer bb1 = Txn.calculateRead(transBase, ()->transObjectFile.read(x3)) ; String s1 = Bytes.fromByteBuffer(bb1) ; assertEquals(str2, s1); // Woot! transBase.getTxnMgr().shutdown(); } }