Beispiel #1
0
  @Test
  public void testCopy() {
    DataAccess da1 = createDataAccess(name);
    da1.create(1001 * 4);
    da1.setHeader(4, 12);
    da1.setInt(1 * 4, 1);
    da1.setInt(123 * 4, 321);
    da1.setInt(1000 * 4, 1111);

    DataAccess da2 = createDataAccess(name + "2");
    da2.create(10);
    da1.copyTo(da2);
    assertEquals(12, da2.getHeader(4));
    assertEquals(1, da2.getInt(1 * 4));
    assertEquals(321, da2.getInt(123 * 4));
    assertEquals(1111, da2.getInt(1000 * 4));

    da2.setInt(1 * 4, 2);
    assertEquals(2, da2.getInt(1 * 4));
    da2.flush();
    da1.flush();
    // make sure they are independent!
    assertEquals(1, da1.getInt(1 * 4));
    da1.close();
    da2.close();
  }
Beispiel #2
0
  @Test
  public void testLoadFlush() {
    DataAccess da = createDataAccess(name);
    assertFalse(da.loadExisting());
    da.create(300);
    da.setInt(7 * 4, 123);
    assertEquals(123, da.getInt(7 * 4));
    da.setInt(10 * 4, Integer.MAX_VALUE / 3);
    assertEquals(Integer.MAX_VALUE / 3, da.getInt(10 * 4));
    da.flush();

    // check noValue clearing
    assertEquals(0, da.getInt(2 * 4));
    assertEquals(0, da.getInt(3 * 4));
    assertEquals(123, da.getInt(7 * 4));
    assertEquals(Integer.MAX_VALUE / 3, da.getInt(10 * 4));
    da.close();

    // cannot load data if already closed
    try {
      da.loadExisting();
      assertTrue(false);
    } catch (Exception ex) {
      assertEquals("already closed", ex.getMessage());
    }

    da = createDataAccess(name);
    assertTrue(da.loadExisting());
    assertEquals(123, da.getInt(7 * 4));
    da.close();
  }
Beispiel #3
0
  @Test
  public void testLoadClose() {
    DataAccess da = createDataAccess(name);
    da.create(300);
    da.setInt(2 * 4, 321);
    da.flush();
    da.close();

    da = createDataAccess(name);
    assertTrue(da.loadExisting());
    assertEquals(321, da.getInt(2 * 4));
    da.close();
  }
Beispiel #4
0
  @Test
  public void testRenameFlush() {
    DataAccess da = createDataAccess(name);
    da.create(100);
    da.setInt(17 * 4, 17);
    da.flush();
    assertTrue(new File(directory + name).exists());
    da.rename(name + "wow");
    assertFalse(new File(directory + name).exists());
    assertTrue(new File(directory + name + "wow").exists());
    assertEquals(17, da.getInt(17 * 4));
    da.close();

    da = createDataAccess(name + "wow");
    assertTrue(da.loadExisting());
    assertEquals(17, da.getInt(17 * 4));
    da.close();
  }
Beispiel #5
0
  @Test
  public void testHeader() {
    DataAccess da = createDataAccess(name);
    da.create(300);
    da.setHeader(7 * 4, 123);
    assertEquals(123, da.getHeader(7 * 4));
    da.setHeader(10 * 4, Integer.MAX_VALUE / 3);
    assertEquals(Integer.MAX_VALUE / 3, da.getHeader(10 * 4));

    da.setHeader(11 * 4, Helper.degreeToInt(123.321));
    assertEquals(123.321, Helper.intToDegree(da.getHeader(11 * 4)), 1e-4);
    da.flush();
    da.close();

    da = createDataAccess(name);
    assertTrue(da.loadExisting());
    assertEquals(123, da.getHeader(7 * 4));
    da.close();
  }
Beispiel #6
0
  @Test
  public void testSegments() {
    DataAccess da = createDataAccess(name);
    da.setSegmentSize(128);
    da.create(10);
    assertEquals(1, da.getSegments());
    da.ensureCapacity(500);
    int olds = da.getSegments();
    assertTrue(olds > 3);

    da.setInt(400, 321);
    da.flush();
    da.close();

    da = createDataAccess(name);
    assertTrue(da.loadExisting());
    assertEquals(olds, da.getSegments());
    assertEquals(321, da.getInt(400));
    da.close();
  }