Esempio n. 1
0
  @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));
  }
Esempio n. 2
0
 @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));
 }
Esempio n. 3
0
 @Test
 public void test_index_record_delete() {
   long recid = engine.put(1000L, Serializer.LONG_SERIALIZER);
   engine.commit();
   assertEquals(1, countIndexRecords());
   engine.delete(recid, Serializer.LONG_SERIALIZER);
   engine.commit();
   assertEquals(0, countIndexRecords());
 }
Esempio n. 4
0
  @Test
  public void test_index_stores_record_size() throws IOException {

    final long recid = engine.put(1, Serializer.INTEGER_SERIALIZER);
    engine.commit();
    assertEquals(
        4, engine.index.getUnsignedShort(recid * 8 + StorageDirect.INDEX_OFFSET_START * 8));
    assertEquals(Integer.valueOf(1), engine.get(recid, Serializer.INTEGER_SERIALIZER));

    engine.update(recid, 1L, Serializer.LONG_SERIALIZER);
    engine.commit();
    assertEquals(
        8, engine.index.getUnsignedShort(recid * 8 + StorageDirect.INDEX_OFFSET_START * 8));
    assertEquals(Long.valueOf(1), engine.get(recid, Serializer.LONG_SERIALIZER));
  }
Esempio n. 5
0
 @Test
 public void test_index_record_delete_and_reusef() {
   long recid = engine.put(1000L, Serializer.LONG_SERIALIZER);
   engine.commit();
   assertEquals(1, countIndexRecords());
   assertEquals(Engine.LAST_RESERVED_RECID + 1, recid);
   engine.delete(recid, Serializer.LONG_SERIALIZER);
   engine.commit();
   assertEquals(0, countIndexRecords());
   long recid2 = engine.put(1000L, Serializer.LONG_SERIALIZER);
   engine.commit();
   // test that previously deleted index slot was reused
   assertEquals(recid, recid2);
   assertEquals(1, countIndexRecords());
   assertNotEquals(0, engine.index.getLong(recid * 8 + StorageDirect.INDEX_OFFSET_START * 8));
 }
Esempio n. 6
0
 @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));
 }
Esempio n. 7
0
 @Test
 public void long_stack_page_created_after_put() throws IOException {
   engine.lock.writeLock().lock();
   engine.longStackPut(TEST_LS_RECID, 111);
   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(1, engine.phys.getByte(pageId));
   assertEquals(0, engine.phys.getLong(pageId) & StorageDirect.PHYS_OFFSET_MASK);
   assertEquals(111, engine.phys.getLong(pageId + 8));
 }
Esempio n. 8
0
  @Test
  public void compact() {
    Map<Long, Long> recids = new HashMap<Long, Long>();
    for (Long l = 0L; l < 1000; l++) {
      recids.put(l, engine.put(l, Serializer.LONG_SERIALIZER));
    }

    engine.commit();
    engine.compact();

    for (Map.Entry<Long, Long> e : recids.entrySet()) {
      Long recid = e.getValue();
      Long value = e.getKey();
      assertEquals(value, engine.get(recid, Serializer.LONG_SERIALIZER));
    }
  }
Esempio n. 9
0
  @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));
  }