@Before public void before() { journal = Journal.create(Location.mem()) ; BufferChannel chan = BufferChannelMem.create("TestTransBlob") ; ComponentId cid = ComponentId.allocLocal() ; transBlob = new TransBlob(cid, chan) ; transactional = TransactionalFactory.createTransactional(journal, transBlob) ; }
@Before public void before() { journal = Journal.create(Location.mem()) ; BufferChannel chan = BufferChannelMem.create("TestTransBlob") ; ComponentId cid = ComponentId.allocLocal() ; transBlob = new TransBlob(cid, chan) ; transactional = TransactionalFactory.createTransactional(journal, transBlob) ; }
@Test public void transBlobFile_3() throws Exception { String str = "Hello World" ; // Write out. { Journal journal = Journal.create(Location.create(DIR)) ; BufferChannel chan = BufferChannelFile.create(DATA) ; ComponentId cid = ComponentId.allocLocal() ; TransBlob transBlob = new TransBlob(cid, chan) ; Transactional transactional = TransactionalFactory.createTransactional(journal, transBlob) ; TestTransBlob.write(transactional, transBlob, str) ; chan.close(); journal.close(); } // Restart { Journal journal = Journal.create(Location.create(DIR)) ; BufferChannel chan = BufferChannelFile.create(DATA) ; ComponentId cid = ComponentId.allocLocal() ; TransBlob transBlob = new TransBlob(cid, chan) ; Transactional transactional = TransactionalFactory.createTransactional(journal, transBlob) ; String s = TestTransBlob.read(transactional, transBlob) ; assertEquals(str, s); } } }
@Test public void transBlobFile_1() throws Exception { Journal journal = Journal.create(Location.create(DIR)) ; BufferChannel chan = BufferChannelFile.create(DATA) ; ComponentId cid = ComponentId.allocLocal() ; TransBlob transBlob = new TransBlob(cid, chan) ; Transactional transactional = TransactionalFactory.createTransactional(journal, transBlob) ; String str = "Hello" ; TestTransBlob.write(transactional, transBlob, str) ; chan.close() ; journal.close() ; String s = FileUtils.readWholeFileAsUTF8(DATA) ; assertEquals(str, s); }
@Test public void transBlobFile_3() throws Exception { String str = "Hello World" ; // Write out. { Journal journal = Journal.create(Location.create(DIR)) ; BufferChannel chan = BufferChannelFile.create(DATA) ; ComponentId cid = ComponentId.allocLocal() ; TransBlob transBlob = new TransBlob(cid, chan) ; Transactional transactional = TransactionalFactory.createTransactional(journal, transBlob) ; TestTransBlob.write(transactional, transBlob, str) ; chan.close(); journal.close(); } // Restart { Journal journal = Journal.create(Location.create(DIR)) ; BufferChannel chan = BufferChannelFile.create(DATA) ; ComponentId cid = ComponentId.allocLocal() ; TransBlob transBlob = new TransBlob(cid, chan) ; Transactional transactional = TransactionalFactory.createTransactional(journal, transBlob) ; String s = TestTransBlob.read(transactional, transBlob) ; assertEquals(str, s); } } }
@Test public void transBlobFile_1() throws Exception { Journal journal = Journal.create(Location.create(DIR)) ; BufferChannel chan = BufferChannelFile.create(DATA) ; ComponentId cid = ComponentId.allocLocal() ; TransBlob transBlob = new TransBlob(cid, chan) ; Transactional transactional = TransactionalFactory.createTransactional(journal, transBlob) ; String str = "Hello" ; TestTransBlob.write(transactional, transBlob, str) ; chan.close() ; journal.close() ; String s = FileUtils.readWholeFileAsUTF8(DATA) ; assertEquals(str, s); }
@Test public void recoverBlobFile_1() throws Exception { String str = "Hello Journal" ; ComponentId cid = ComponentId.allocLocal() ; // ComponentIdRegistry registry = new ComponentIdRegistry() ; // registry.register(cid, "Blob", 1) ; // Write out a journal. { Journal journal = Journal.create(Location.create(dir.getRoot().getAbsolutePath())) ; journal.write(JournalEntryType.REDO, cid, L.stringToByteBuffer(str)) ; journal.writeJournal(JournalEntry.COMMIT) ; journal.close(); } TransactionCoordinator coord = new TransactionCoordinator(Location.create(dir.getRoot().getAbsolutePath())) ; BufferChannel chan = BufferChannelFile.create(data) ; TransBlob tBlob = new TransBlob(cid, chan) ; coord.add(tBlob) ; coord.start(); ByteBuffer blob = tBlob.getBlob() ; assertNotNull(blob); String s = L.byteBufferToString(blob) ; assertEquals(str,s) ; coord.shutdown(); }
@Test public void recoverBlobFile_1() throws Exception { String str = "Hello Journal" ; ComponentId cid = ComponentId.allocLocal() ; // ComponentIdRegistry registry = new ComponentIdRegistry() ; // registry.register(cid, "Blob", 1) ; // Write out a journal. { Journal journal = Journal.create(Location.create(dir.getRoot().getAbsolutePath())) ; journal.write(JournalEntryType.REDO, cid, L.stringToByteBuffer(str)) ; journal.writeJournal(JournalEntry.COMMIT) ; journal.close(); } TransactionCoordinator coord = new TransactionCoordinator(Location.create(dir.getRoot().getAbsolutePath())) ; BufferChannel chan = BufferChannelFile.create(data) ; TransBlob tBlob = new TransBlob(cid, chan) ; coord.add(tBlob) ; coord.start(); ByteBuffer blob = tBlob.getBlob() ; assertNotNull(blob); String s = L.byteBufferToString(blob) ; assertEquals(str,s) ; coord.shutdown(); }
@Test public void transBlobFile_2() throws Exception { Journal journal = Journal.create(Location.create(DIR)) ; BufferChannel chan = BufferChannelFile.create(DATA) ; ComponentId cid = ComponentId.allocLocal() ; TransBlob transBlob = new TransBlob(cid, chan) ; Transactional transactional = TransactionalFactory.createTransactional(journal, transBlob) ; String str = "Hello1" ; Txn.executeWrite(transactional, ()->{ transBlob.setString("one"); }) ; Txn.executeWrite(transactional, ()->{ transBlob.setString("two"); }) ; chan.close() ; journal.close() ; String s = FileUtils.readWholeFileAsUTF8(DATA) ; assertEquals("two", s); }
@Test public void transBlobFile_2() throws Exception { Journal journal = Journal.create(Location.create(DIR)) ; BufferChannel chan = BufferChannelFile.create(DATA) ; ComponentId cid = ComponentId.allocLocal() ; TransBlob transBlob = new TransBlob(cid, chan) ; Transactional transactional = TransactionalFactory.createTransactional(journal, transBlob) ; String str = "Hello1" ; Txn.executeWrite(transactional, ()->{ transBlob.setString("one"); }) ; Txn.executeWrite(transactional, ()->{ transBlob.setString("two"); }) ; chan.close() ; journal.close() ; String s = FileUtils.readWholeFileAsUTF8(DATA) ; assertEquals("two", s); }