示例#1
0
  @Test
  public void testCreateIndexedSpeed() throws Exception {
    idbm.wipeDatabase();

    Random r = new Random(1L);
    for (int test = 0; test < 1000; test++) {
      TestThrift tt =
          new TestThrift(
              null,
              r.nextInt(),
              r.nextLong(),
              r.nextBoolean(),
              (byte) r.nextInt(),
              (short) r.nextInt(),
              r.nextDouble(),
              generateString(r, 16),
              "abc");
      idbm.create(tt);

      idbm.commit();
    }

    for (int test = 0; test < 1000; test++) {
      // NOTE(jgauci): We never have collisions with the ids above
      TestThrift tt =
          new TestThrift(
              String.valueOf(100000 + r.nextInt()),
              r.nextInt(),
              r.nextLong(),
              r.nextBoolean(),
              (byte) r.nextInt(),
              (short) r.nextInt(),
              r.nextDouble(),
              generateString(r, 16),
              "abc");
      idbm.createWithId(tt);

      idbm.commit();
    }

    idbm.wipeDatabase();
  }
示例#2
0
  @Test
  public void testCreateIndexed() throws Exception {
    idbm.wipeDatabase();

    Random r = new Random(1L);
    for (int test = 0; test < 100; test++) {
      TestThrift tt =
          new TestThrift(
              null,
              r.nextInt(),
              r.nextLong(),
              r.nextBoolean(),
              (byte) r.nextInt(),
              (short) r.nextInt(),
              r.nextDouble(),
              generateString(r, 16),
              "abc");
      idbm.create(tt);
      idbm.commit();

      // System.out.println(tt);
      Assert.assertEquals(tt, getLast(idbm.secondaryGet(tt.getClass(), "id", tt.id)));
      Assert.assertEquals(tt, getLast(idbm.secondaryGet(tt.getClass(), "i", tt.i)));
      Assert.assertEquals(tt, getLast(idbm.secondaryGet(tt.getClass(), "l", tt.l)));
      Assert.assertEquals(tt, getLast(idbm.secondaryGet(tt.getClass(), "b", tt.b)));
      Assert.assertEquals(tt, getLast(idbm.secondaryGet(tt.getClass(), "by", tt.by)));
      Assert.assertEquals(tt, getLast(idbm.secondaryGet(tt.getClass(), "s", tt.s)));
      try {
        idbm.secondaryGet(tt.getClass(), "d", tt.d);
        Assert.fail("Expected an exception");
      } catch (IOException e) {
      }
      Assert.assertEquals(tt, getLast(idbm.secondaryGet(tt.getClass(), "st", tt.st)));
      try {
        idbm.secondaryGet(tt.getClass(), "notIndexedString", tt.notIndexedString);
        Assert.fail("Expected an exception");
      } catch (IOException e) {
      }
    }

    for (int test = 0; test < 100; test++) {
      // NOTE(jgauci): We never have collisions with the ids above
      TestThrift tt =
          new TestThrift(
              String.valueOf(100000 + r.nextInt(100000)),
              r.nextInt(),
              r.nextLong(),
              r.nextBoolean(),
              (byte) r.nextInt(),
              (short) r.nextInt(),
              r.nextDouble(),
              generateString(r, 16),
              "abc");
      idbm.createWithId(tt);
      idbm.commit();

      // System.out.println(tt);
      Assert.assertEquals(tt, getLast(idbm.secondaryGet(tt.getClass(), "id", tt.id)));
      Assert.assertEquals(tt, getLast(idbm.secondaryGet(tt.getClass(), "i", tt.i)));
      Assert.assertEquals(tt, getLast(idbm.secondaryGet(tt.getClass(), "l", tt.l)));
      Assert.assertEquals(tt, getLast(idbm.secondaryGet(tt.getClass(), "b", tt.b)));
      Assert.assertEquals(tt, getLast(idbm.secondaryGet(tt.getClass(), "by", tt.by)));
      Assert.assertEquals(tt, getLast(idbm.secondaryGet(tt.getClass(), "s", tt.s)));
      Assert.assertEquals(tt, getLast(idbm.secondaryGet(tt.getClass(), "st", tt.st)));
      try {
        idbm.secondaryGet(tt.getClass(), "d", tt.d);
        Assert.fail("Expected an exception");
      } catch (IOException e) {
      }
      Assert.assertEquals(tt, getLast(idbm.secondaryGet(tt.getClass(), "st", tt.st)));
      try {
        idbm.secondaryGet(tt.getClass(), "notIndexedString", tt.notIndexedString);
        Assert.fail("Expected an exception");
      } catch (IOException e) {
      }
    }

    for (int test = 0; test < 100; test++) {
      // NOTE(jgauci): We never have collisions with the ids above
      TestThrift tt =
          new TestThrift(
              String.valueOf(200000 + r.nextInt(100000)),
              r.nextInt(),
              r.nextLong(),
              r.nextBoolean(),
              (byte) r.nextInt(),
              (short) r.nextInt(),
              r.nextDouble(),
              null,
              "abc");
      idbm.createWithId(tt);
      idbm.commit();

      // System.out.println(tt);
      Assert.assertEquals(tt, getLast(idbm.secondaryGet(tt.getClass(), "id", tt.id)));
      Assert.assertEquals(tt, getLast(idbm.secondaryGet(tt.getClass(), "i", tt.i)));
      Assert.assertEquals(tt, getLast(idbm.secondaryGet(tt.getClass(), "l", tt.l)));
      Assert.assertEquals(tt, getLast(idbm.secondaryGet(tt.getClass(), "b", tt.b)));
      Assert.assertEquals(tt, getLast(idbm.secondaryGet(tt.getClass(), "by", tt.by)));
      Assert.assertEquals(tt, getLast(idbm.secondaryGet(tt.getClass(), "s", tt.s)));
      try {
        idbm.secondaryGet(tt.getClass(), "d", tt.d);
        Assert.fail("Expected an exception");
      } catch (IOException e) {
      }
      Assert.assertEquals(0, idbm.secondaryGet(tt.getClass(), "st", tt.st).size());
      try {
        idbm.secondaryGet(tt.getClass(), "notIndexedString", tt.notIndexedString);
        Assert.fail("Expected an exception");
      } catch (IOException e) {
      }
    }

    idbm.wipeDatabase();
  }