コード例 #1
0
 private void dropTable(final String tableName) {
   connector
       .getDBI()
       .withHandle(
           new HandleCallback<Void>() {
             @Override
             public Void withHandle(Handle handle) throws Exception {
               handle.createStatement(String.format("DROP TABLE %s", tableName)).execute();
               return null;
             }
           });
 }
コード例 #2
0
  @Test
  public void testInsertOrUpdate() throws Exception {
    final String tableName = "test";
    connector.createConfigTable(tableName);

    Assert.assertNull(connector.lookup(tableName, "name", "payload", "emperor"));

    connector.insertOrUpdate(tableName, "name", "payload", "emperor", "penguin".getBytes());
    Assert.assertArrayEquals(
        "penguin".getBytes(), connector.lookup(tableName, "name", "payload", "emperor"));

    connector.insertOrUpdate(tableName, "name", "payload", "emperor", "penguin chick".getBytes());

    Assert.assertArrayEquals(
        "penguin chick".getBytes(), connector.lookup(tableName, "name", "payload", "emperor"));

    dropTable(tableName);
  }
コード例 #3
0
  @Test
  public void testCreateTables() throws Exception {
    final LinkedList<String> tables = new LinkedList<String>();
    final String entryType = tablesConfig.getTaskEntryType();
    tables.add(tablesConfig.getConfigTable());
    tables.add(tablesConfig.getSegmentsTable());
    tables.add(tablesConfig.getRulesTable());
    tables.add(tablesConfig.getLockTable(entryType));
    tables.add(tablesConfig.getLogTable(entryType));
    tables.add(tablesConfig.getEntryTable(entryType));
    tables.add(tablesConfig.getAuditTable());

    connector.createSegmentTable();
    connector.createConfigTable();
    connector.createRulesTable();
    connector.createTaskTables();
    connector.createAuditTable();

    connector
        .getDBI()
        .withHandle(
            new HandleCallback<Void>() {
              @Override
              public Void withHandle(Handle handle) throws Exception {
                for (String table : tables) {
                  Assert.assertTrue(
                      String.format("table %s was not created!", table),
                      connector.tableExists(handle, table));
                }

                return null;
              }
            });

    for (String table : tables) {
      dropTable(table);
    }
  }