Ejemplo n.º 1
0
  @Test
  public void testQuery() {
    create();
    for (int i = 0; i < ITERATIONS; ++i) {
      final int selectedClusterId =
          clusterIds[((int) (Math.abs(hashFunction.hashCode(i)) % clusterIds.length))];

      Iterable<ODocument> resultSet =
          database.command(new OCommandSQL("select from AutoShardingTest where id = ?")).execute(i);
      Assert.assertTrue(resultSet.iterator().hasNext());
      final ODocument sqlRecord = resultSet.iterator().next();
      Assert.assertEquals(sqlRecord.getIdentity().getClusterId(), selectedClusterId);
    }
  }
Ejemplo n.º 2
0
  private void create() {
    for (int i = 0; i < ITERATIONS; ++i) {
      final int selectedClusterId =
          clusterIds[((int) (Math.abs(hashFunction.hashCode(i)) % clusterIds.length))];

      ODocument sqlRecord =
          database
              .command(new OCommandSQL("insert into AutoShardingTest (id) values (" + i + ")"))
              .execute();
      Assert.assertEquals(sqlRecord.getIdentity().getClusterId(), selectedClusterId);

      ODocument apiRecord = new ODocument("AutoShardingTest").field("id", i).save();
      Assert.assertEquals(apiRecord.getIdentity().getClusterId(), selectedClusterId);
    }

    // TEST ALL CLUSTER HAVE RECORDS
    for (int clusterId : cls.getClusterIds()) {
      Assert.assertTrue(database.countClusterElements(clusterId) > 0);
    }
  }