/** Test initializing the last position in the logs. */ public void testSetLastPosition() throws DatabaseException { /* * Pretend that the last file is file 79. */ fileManager.setLastPosition( // next available LSN DbLsn.makeLsn(79L, 88L), DbLsn.makeLsn(79L, 77), 66L); /* Put an entry down, should fit within file 79. */ fileManager.bumpLsn(11L); assertEquals(DbLsn.makeLsn(79L, 88L), fileManager.getLastUsedLsn()); assertEquals(77L, fileManager.getPrevEntryOffset()); /* Put another entry in, should go to the next file. */ fileManager.bumpLsn(22L); assertEquals( DbLsn.makeLsn(80L, FileManager.firstLogEntryOffset()), fileManager.getLastUsedLsn()); assertEquals(0, fileManager.getPrevEntryOffset()); }
/** Test LSN administration. */ public void testLsnBumping() throws Exception { /* We are adding these entries: +----+------+---------+--------+ file 0: |hdr | 30 | 50 |empty | +----+------+---------+--------+ 0 hdr hdr+30 hdr+80 99 +----+--------+-------+-------+-----+-------+ file 1: |hdr | 40 | 20 | 10 | 5 | empty | +----+--------+-------+-------+-----+-------+ 0 hdr hdr+40 hdr+60 hdr+70 hdr+75 +-----+-----+--------+ file 2: | hdr | 75 | empty | +-----+-----+--------+ 0 hdr hdr+75 +-----+-------------------------------+ file 3: | hdr | 125 | +-----+-------------------------------+ 0 hdr +-----+-----+------+-----+--------------+ file 4: | hdr | 10 | 20 | 30 | empty +-----+-----+------+-----+--------------+ 0 hdr hdr+10 hdr+30 */ try { /* Should start out at LSN 0. */ /* "add" some entries to the log. */ long hdrSize = FileManager.firstLogEntryOffset(); fileManager.bumpLsn(30L); /* Item placed here. */ assertEquals(DbLsn.makeLsn(0, hdrSize), fileManager.getLastUsedLsn()); /* prev entry. */ assertEquals(0, fileManager.getPrevEntryOffset()); fileManager.bumpLsn(50L); /* Item placed here. */ assertEquals(DbLsn.makeLsn(0, (hdrSize + 30)), fileManager.getLastUsedLsn()); assertEquals(hdrSize, fileManager.getPrevEntryOffset()); /* bump over to a file 1. */ fileManager.bumpLsn(40L); /* item placed here. */ assertEquals(DbLsn.makeLsn(1, hdrSize), fileManager.getLastUsedLsn()); assertEquals(0, fileManager.getPrevEntryOffset()); fileManager.bumpLsn(20L); /* Item placed here. */ assertEquals(DbLsn.makeLsn(1, (hdrSize + 40)), fileManager.getLastUsedLsn()); assertEquals(hdrSize, fileManager.getPrevEntryOffset()); fileManager.bumpLsn(10L); /* Item placed here. */ assertEquals(DbLsn.makeLsn(1, (hdrSize + 60)), fileManager.getLastUsedLsn()); assertEquals(hdrSize + 40, fileManager.getPrevEntryOffset()); fileManager.bumpLsn(5L); /* item placed here. */ assertEquals(DbLsn.makeLsn(1, (hdrSize + 70)), fileManager.getLastUsedLsn()); assertEquals(hdrSize + 60, fileManager.getPrevEntryOffset()); /* bump over to file 2. */ fileManager.bumpLsn(75L); /* Item placed here. */ assertEquals(DbLsn.makeLsn(2, hdrSize), fileManager.getLastUsedLsn()); assertEquals(0, fileManager.getPrevEntryOffset()); /* Ask for something bigger than a file: bump over to file 3. */ fileManager.bumpLsn(125L); /* item placed here. */ assertEquals(DbLsn.makeLsn(3, hdrSize), fileManager.getLastUsedLsn()); assertEquals(0, fileManager.getPrevEntryOffset()); /* bump over to file 4. */ fileManager.bumpLsn(10L); /* Item placed here. */ assertEquals(DbLsn.makeLsn(4, hdrSize), fileManager.getLastUsedLsn()); assertEquals(0, fileManager.getPrevEntryOffset()); fileManager.bumpLsn(20L); /* Item placed here. */ assertEquals(DbLsn.makeLsn(4, (hdrSize + 10)), fileManager.getLastUsedLsn()); assertEquals(hdrSize, fileManager.getPrevEntryOffset()); fileManager.bumpLsn(30L); /* Item placed here. */ assertEquals(DbLsn.makeLsn(4, (hdrSize + 30)), fileManager.getLastUsedLsn()); assertEquals((hdrSize + 10), fileManager.getPrevEntryOffset()); } catch (Exception e) { e.printStackTrace(); throw e; } }