@Test public void long_stack_page_overflow() throws IOException { engine.lock.writeLock().lock(); // fill page until near overflow for (int i = 0; i < StorageDirect.LONG_STACK_NUM_OF_RECORDS_PER_PAGE; i++) { engine.longStackPut(TEST_LS_RECID, 1000L + i); } engine.commit(); // check content long pageId = engine.index.getLong(TEST_LS_RECID * 8); assertEquals(StorageDirect.LONG_STACK_PAGE_SIZE, pageId >>> 48); pageId = pageId & StorageDirect.PHYS_OFFSET_MASK; assertEquals(8L, pageId); assertEquals(StorageDirect.LONG_STACK_NUM_OF_RECORDS_PER_PAGE, engine.phys.getByte(pageId)); for (int i = 0; i < StorageDirect.LONG_STACK_NUM_OF_RECORDS_PER_PAGE; i++) { assertEquals(1000L + i, engine.phys.getLong(pageId + 8 + i * 8)); } // add one more item, this will trigger page overflow engine.longStackPut(TEST_LS_RECID, 11L); engine.commit(); // check page overflowed pageId = engine.index.getLong(TEST_LS_RECID * 8); assertEquals(StorageDirect.LONG_STACK_PAGE_SIZE, pageId >>> 48); pageId = pageId & StorageDirect.PHYS_OFFSET_MASK; assertEquals(8L + StorageDirect.LONG_STACK_PAGE_SIZE, pageId); assertEquals(1, engine.phys.getByte(pageId)); assertEquals(8L, engine.phys.getLong(pageId) & StorageDirect.PHYS_OFFSET_MASK); assertEquals(11L, engine.phys.getLong(pageId + 8)); }
@Test public void test_long_stack_puts_record_size_into_index() throws IOException { engine.lock.writeLock().lock(); engine.longStackPut(TEST_LS_RECID, 1); engine.commit(); assertEquals( StorageDirect.LONG_STACK_PAGE_SIZE, engine.index.getUnsignedShort(TEST_LS_RECID * 8)); }
@Test public void long_stack_page_deleted_after_take() throws IOException { engine.lock.writeLock().lock(); engine.longStackPut(TEST_LS_RECID, 111); engine.commit(); assertEquals(111L, engine.longStackTake(TEST_LS_RECID)); engine.commit(); assertEquals(0L, engine.index.getLong(TEST_LS_RECID * 8)); }
@Test public void long_stack_put_five() throws IOException { engine.lock.writeLock().lock(); engine.longStackPut(TEST_LS_RECID, 111); engine.longStackPut(TEST_LS_RECID, 112); engine.longStackPut(TEST_LS_RECID, 113); engine.longStackPut(TEST_LS_RECID, 114); engine.longStackPut(TEST_LS_RECID, 115); engine.commit(); long pageId = engine.index.getLong(TEST_LS_RECID * 8); assertEquals(StorageDirect.LONG_STACK_PAGE_SIZE, pageId >>> 48); pageId = pageId & StorageDirect.PHYS_OFFSET_MASK; assertEquals(8L, pageId); assertEquals(5, engine.phys.getByte(pageId)); assertEquals(0, engine.phys.getLong(pageId) & StorageDirect.PHYS_OFFSET_MASK); assertEquals(111, engine.phys.getLong(pageId + 8)); assertEquals(112, engine.phys.getLong(pageId + 16)); assertEquals(113, engine.phys.getLong(pageId + 24)); assertEquals(114, engine.phys.getLong(pageId + 32)); assertEquals(115, engine.phys.getLong(pageId + 40)); }
@Test public void test_long_stack_put_take() throws IOException { engine.lock.writeLock().lock(); final long max = 150; for (long i = 1; i < max; i++) { engine.longStackPut(TEST_LS_RECID, i); } for (long i = max - 1; i > 0; i--) { assertEquals(i, engine.longStackTake(TEST_LS_RECID)); } assertEquals(0, getLongStack(TEST_LS_RECID).size()); }
@Test public void test_basic_long_stack() throws IOException { // dirty hack to make sure we have lock engine.lock.writeLock().lock(); final long max = 150; ArrayList<Long> list = new ArrayList<Long>(); for (long i = 1; i < max; i++) { engine.longStackPut(TEST_LS_RECID, i); list.add(i); } Collections.reverse(list); engine.commit(); assertEquals(list, getLongStack(TEST_LS_RECID)); }
@Test public void test_long_stack_put_take_simple() throws IOException { engine.lock.writeLock().lock(); engine.longStackPut(TEST_LS_RECID, 111); assertEquals(111L, engine.longStackTake(TEST_LS_RECID)); }