@Test
	public void testRecoveryWithUndoRedo() throws Exception {

		DBHandle dbh = init(RECORD_COUNT);
		DBHandle dbh2 = null;
		try {

			assertTrue(dbh.undo());
			assertTrue(dbh.undo());

			assertTrue(dbh.takeRecoverySnapshot(null, TaskMonitor.DUMMY));

			assertTrue(dbh.redo());
			assertTrue(dbh.redo());

			assertTrue(dbh.takeRecoverySnapshot(null, TaskMonitor.DUMMY));

			assertNotNull(dbh.getTable("table2"));

			DatabaseItem dbItem = (DatabaseItem) fileSystem.getItem("/", "testDb");
			assertTrue(dbItem.canRecover());
			BufferFile bf = dbItem.openForUpdate(FolderItem.DEFAULT_CHECKOUT_ID);
			dbh2 = new DBHandle(bf, true, TaskMonitor.DUMMY);

			Table table1 = dbh2.getTable("table1");
			assertNotNull(table1);
			assertEquals(RECORD_COUNT / 2, table1.getRecordCount());

			for (int i = 0; i < RECORD_COUNT; i += 2) {
				DBRecord rec = table1.getRecord(i);
				assertNull(rec);
			}

			for (int i = 1; i < RECORD_COUNT; i += 2) {
				DBRecord rec = table1.getRecord(i);
				assertNotNull(rec);
				assertEquals("initTable1_" + i, rec.getString(0));
			}

			Table table2 = dbh2.getTable("table2");
			assertNotNull(table2);
			assertEquals(RECORD_COUNT / 2, table2.getRecordCount());

			for (int i = 0; i < RECORD_COUNT; i += 2) {
				assertNull(table2.getRecord(i));
			}

			for (int i = 1; i < RECORD_COUNT; i += 2) {
				DBRecord rec = table2.getRecord(i);
				assertNotNull(rec);
				assertEquals("initTable2_" + i, rec.getString(0));
			}
		}
		finally {
			dbh.close();
			if (dbh2 != null) {
				dbh2.close();
			}
		}

	}
File created:


Recovery snapshot taken after each transaction.
Transaction 1:

Transaction 2:

Transaction 3:

Transaction 4:


@throws Exception
Ghidra/Framework/FileSystem/src/test/java/db/RecoveryDBTest.java