Ejemplo n.º 1
0
  public void testRankWithTimestamp() throws Exception {
    Client client = getClient();

    long baseTime = TimestampType.millisFromJDBCformat("1953-06-10 00:00:00");
    long input[][] = expected.clone();
    shuffleArrayOfLongs(input);
    ClientResponse cr;
    VoltTable vt;
    for (long[] row : input) {
      cr =
          client.callProcedure(
              "T_TIMESTAMP.insert",
              row[colA],
              row[colB],
              new TimestampType(baseTime + row[colB] * 1000));
      assertEquals(ClientResponse.SUCCESS, cr.getStatus());
    }
    String sql =
        "select A, B, C, rank() over (partition by A order by C) as R from T_TIMESTAMP ORDER BY A, B, C, R;";
    cr = client.callProcedure("@AdHoc", sql);
    assertEquals(ClientResponse.SUCCESS, cr.getStatus());
    vt = cr.getResults()[0];
    assertEquals(expected.length, vt.getRowCount());
    for (int rowIdx = 0; vt.advanceRow(); rowIdx += 1) {
      String msg = String.format("Row %d:", rowIdx);
      assertEquals(msg, expected[rowIdx][colA], vt.getLong(0));
      assertEquals(msg, expected[rowIdx][colB], vt.getLong(1));
      assertEquals(msg, baseTime + expected[rowIdx][colB] * 1000, vt.getTimestampAsLong(2));
      assertEquals(msg, expected[rowIdx][colR_A], vt.getLong(3));
    }
  }
Ejemplo n.º 2
0
 public void testAggregatesOnEmptyTable() throws IOException, ProcCallException {
   String[] aggs = {"count", "sum", "min", "max"};
   String[] tables = {"P1", "R1"};
   for (String table : tables) {
     Client client = getClient();
     for (int i = 0; i < aggs.length; ++i) {
       String query = String.format("select %s(%s.NUM) from %s", aggs[i], table, table);
       VoltTable[] results = client.callProcedure("@AdHoc", query).getResults();
       if (aggs[i].equals("count")) {
         assertEquals(0, results[0].asScalarLong());
       } else {
         final VoltTableRow row = results[0].fetchRow(0);
         row.get(0, results[0].getColumnType(0));
         if (!isHSQL()) {
           assertTrue(row.wasNull());
         }
       }
     }
     // Do avg separately since the column is a float and makes
     // asScalarLong() unhappy
     String query = String.format("select avg(%s.NUM) from %s", table, table);
     VoltTable[] results = client.callProcedure("@AdHoc", query).getResults();
     results[0].advanceRow();
     @SuppressWarnings("unused")
     final double value = ((Number) results[0].get(0, results[0].getColumnType(0))).doubleValue();
     if (!isHSQL()) {
       assertTrue(results[0].wasNull());
     }
   }
 }
  public void testSneakingInAProc() throws IOException {
    System.out.println("STARTING testSneakingInAProc");
    Client client = getClient();

    int ctr = 0;
    for (int i = 0; i < 10; i++) {
      client.callProcedure(new MPCallback(), "MultiPartition");
      ctr++;
      client.callProcedure(new SPCallback(), "SinglePartition", ctr, ctr);
      ctr++;
      client.callProcedure(new SPCallback(), "SinglePartition", ctr, ctr);
      ctr++;
      client.callProcedure(new SPCallback(), "SinglePartition", ctr, ctr);
      ctr++;
      client.callProcedure(new SPCallback(), "SinglePartition", ctr, ctr);
      ctr++;
    }

    answersReceived.addAndGet(ctr);

    client.drain();

    while (answersReceived.get() > 0) {
      try {
        Thread.sleep(1000);
      } catch (InterruptedException e) {
        e.printStackTrace();
      }
    }
  }
  public void testStatistics_Procedure() throws Exception {
    Client client = getClient();
    VoltTable results[] = null;
    // 3 seconds translates to 3 billion nanos, which overflows internal
    // values (ENG-1039)
    results = client.callProcedure("GoSleep", 3000, 0, null).getResults();
    results = client.callProcedure("@Statistics", "procedure", 0).getResults();
    // one aggregate table returned
    assertTrue(results.length == 1);
    System.out.println("Test procedures table: " + results[0].toString());

    VoltTable stats = results[0];
    stats.advanceRow();
    // Check for overflow
    long min_time = (Long) stats.get("MIN_EXECUTION_TIME", VoltType.BIGINT);
    long max_time = (Long) stats.get("MAX_EXECUTION_TIME", VoltType.BIGINT);
    long avg_time = (Long) stats.get("AVG_EXECUTION_TIME", VoltType.BIGINT);
    assertTrue("Failed MIN_EXECUTION_TIME > 0, value was: " + min_time, min_time > 0);
    assertTrue("Failed MAX_EXECUTION_TIME > 0, value was: " + max_time, max_time > 0);
    assertTrue("Failed AVG_EXECUTION_TIME > 0, value was: " + avg_time, avg_time > 0);

    // check for reasonable values
    assertTrue(
        "Failed MIN_EXECUTION_TIME > 2,400,000,000ns, value was: " + min_time,
        min_time > 2400000000L);
    assertTrue(
        "Failed MAX_EXECUTION_TIME > 2,400,000,000ns, value was: " + max_time,
        max_time > 2400000000L);
    assertTrue(
        "Failed AVG_EXECUTION_TIME > 2,400,000,000ns, value was: " + avg_time,
        avg_time > 2400000000L);
  }
Ejemplo n.º 5
0
  public void testExplain() throws IOException, ProcCallException {
    Client client = getClient();
    VoltTable vt = null;

    String[] strs = {
      "SELECT COUNT(*) FROM T1 order by A_INT", "SELECT COUNT(*) FROM T1 order by A_INT"
    };

    vt = client.callProcedure("@Explain", (Object[]) strs).getResults()[0];
    while (vt.advanceRow()) {
      System.out.println(vt);
      String plan = vt.getString("EXEcution_PlaN");
      assertTrue(plan.contains("RETURN RESULTS TO STORED PROCEDURE"));
      // Validate bypass of no-op sort on single-row result.
      assertFalse(plan.contains("ORDER BY (SORT)"));
      assertTrue(plan.contains("TABLE COUNT"));
    }

    // test the index count node
    vt = client.callProcedure("@Explain", "SELECT COUNT(*) FROM t3 where I3 < 100").getResults()[0];
    while (vt.advanceRow()) {
      System.out.println(vt);
      String plan = vt.getString(0);
      assertTrue(plan.contains("INDEX COUNT"));
    }

    // test expression index usage
    vt = client.callProcedure("@Explain", "SELECT * FROM t3 where I3 + I4 < 100").getResults()[0];
    while (vt.advanceRow()) {
      System.out.println(vt);
      String plan = vt.getString(0);
      assertTrue(plan.contains("INDEX SCAN"));
    }
  }
Ejemplo n.º 6
0
  /**
   * Check the result of a query that has only an OFFSET and no LIMIT clause. This is done by
   * executing the query with and without the offset clause, and then skipping past the offset rows
   * in the expected table here on the client side.
   */
  private static void doOffsetAndCheck(Client client, String stmt)
      throws IOException, InterruptedException, ProcCallException {
    String stmtNoOffset = stmt.substring(0, stmt.indexOf("OFFSET"));
    VoltTable expectedTable = client.callProcedure("@AdHoc", stmtNoOffset).getResults()[0];
    int rowCountBeforeOffset = expectedTable.getRowCount();

    int[] offsets = {0, 1, 5, 10, 11, 15};
    for (int offset : offsets) {
      VoltTable actualTable = client.callProcedure("@AdHoc", stmt, offset).getResults()[0];
      int expectedRowCount = Math.max(rowCountBeforeOffset - offset, 0);
      assertEquals(
          "Actual table has wrong number of rows: ", expectedRowCount, actualTable.getRowCount());
      if (actualTable.getRowCount() == 0) continue;

      // non-empty result.
      // Advance expected table past offset
      // then compare what's left.
      actualTable.resetRowPosition();
      for (int i = 0; i < offset; ++i) expectedTable.advanceRow();

      while (actualTable.advanceRow() && expectedTable.advanceRow()) {
        assertEquals(expectedTable.getLong(0), actualTable.getLong(0));
        assertEquals(expectedTable.getLong(1), actualTable.getLong(1));
      }
    }
  }
Ejemplo n.º 7
0
 public void testInvalidCalls() throws Exception {
   System.out.println("\n\nTESTING INVALID CALLS\n\n\n");
   Client client = getFullyConnectedClient();
   //
   // invalid selector
   //
   try {
     // No selector at all.
     client.callProcedure("@Statistics");
     fail();
   } catch (ProcCallException ex) {
     // All badness gets turned into ProcCallExceptions, so we need
     // to check specifically for this error, otherwise things that
     // crash the cluster also turn into ProcCallExceptions and don't
     // trigger failure (ENG-2347)
     assertEquals(
         "Incorrect number of arguments to @Statistics (expects 2, received 0)", ex.getMessage());
   }
   try {
     // extra stuff
     client.callProcedure("@Statistics", "table", 0, "OHHAI");
     fail();
   } catch (ProcCallException ex) {
     assertEquals(
         "Incorrect number of arguments to @Statistics (expects 2, received 3)", ex.getMessage());
   }
   try {
     // Invalid selector
     client.callProcedure("@Statistics", "garbage", 0);
     fail();
   } catch (ProcCallException ex) {
   }
 }
Ejemplo n.º 8
0
 public void testGiantDelete() throws IOException, ProcCallException {
   /*
    * Times out with valgrind
    */
   if (isValgrind()) {
     return;
   }
   Client client = getClient(1000 * 60 * 10);
   for (int i = 0; i < 100; i++) {
     client.callProcedure("InsertBatch", 200000, 0, i * 200000);
   }
   try {
     client.callProcedure("Delete");
   } catch (ProcCallException pce) {
     pce.printStackTrace();
     fail("Expected to be able to delete large batch but failed");
   }
   // Test repeatability
   for (int i = 0; i < 100; i++) {
     client.callProcedure("InsertBatch", 200000, 0, i * 200000);
   }
   try {
     client.callProcedure("Delete");
   } catch (ProcCallException pce) {
     pce.printStackTrace();
     fail("Expected to be able to delete large batch but failed");
   }
 }
Ejemplo n.º 9
0
 public void testStringMinMaxAndCount() throws IOException, ProcCallException {
   String[] tables = {"P1", "R1"};
   for (String table : tables) {
     Client client = getClient();
     for (int i = 0; i < ROWS; ++i) {
       client.callProcedure(
           "Insert", table, i, String.valueOf(i), new BigDecimal(10.0), i / 2, 14.5);
     }
     for (int i = ROWS; i < ROWS + 5; ++i) {
       client.callProcedure(
           "Insert", table, i, VoltType.NULL_STRING, new BigDecimal(10.0), i / 2, 14.5);
     }
     String query = String.format("select MIN(%s.DESC) from %s", table, table);
     VoltTable[] results = client.callProcedure("@AdHoc", query).getResults();
     results[0].advanceRow();
     assertEquals("0", results[0].getString(0));
     query = String.format("select MAX(%s.DESC) from %s", table, table);
     results = client.callProcedure("@AdHoc", query).getResults();
     results[0].advanceRow();
     assertEquals("9", results[0].getString(0));
     query = String.format("select COUNT(%s.DESC) from %s", table, table);
     results = client.callProcedure("@AdHoc", query).getResults();
     assertEquals(ROWS, results[0].asScalarLong());
   }
 }
Ejemplo n.º 10
0
  public void validateRankFunction(String sql, int expectedCol) throws Exception {
    Client client = getClient();

    long input[][] = expected.clone();
    shuffleArrayOfLongs(input);
    ClientResponse cr;
    VoltTable vt;

    cr = client.callProcedure("@AdHoc", "TRUNCATE TABLE T");
    assertEquals(ClientResponse.SUCCESS, cr.getStatus());
    for (long[] row : input) {
      cr = client.callProcedure("T.insert", row[colA], row[colB], row[colC]);
      assertEquals(ClientResponse.SUCCESS, cr.getStatus());
    }
    cr = client.callProcedure("@AdHoc", sql);
    assertEquals(ClientResponse.SUCCESS, cr.getStatus());
    vt = cr.getResults()[0];
    for (int rowIdx = 0; vt.advanceRow(); rowIdx += 1) {
      String msg = String.format("Row %d:", rowIdx);
      assertEquals(msg, expected[rowIdx][colA], vt.getLong(0));
      assertEquals(msg, expected[rowIdx][colB], vt.getLong(1));
      assertEquals(msg, expected[rowIdx][colC], vt.getLong(2));
      assertEquals(msg, expected[rowIdx][expectedCol], vt.getLong(3));
    }
  }
Ejemplo n.º 11
0
 private void initUniqueTable(Client client)
     throws NoConnectionsException, IOException, ProcCallException {
   client.callProcedure("tu.insert", 10, 2);
   client.callProcedure("tu.insert", 20, 1);
   client.callProcedure("tu.insert", 30, 1);
   client.callProcedure("tu.insert", 40, 3);
   client.callProcedure("tu.insert", 50, 1);
 }
Ejemplo n.º 12
0
  public void testENG1808() throws IOException, ProcCallException {
    Client client = this.getClient();

    client.callProcedure("A.insert", 1, 1);

    VoltTable result = client.callProcedure("@AdHoc", "select I from A limit 0").getResults()[0];

    assertEquals(0, result.getRowCount());
  }
 public void testMultiPartitionInsert() throws IOException, ProcCallException {
   Client client = getClient();
   VoltTable[] results =
       client.callProcedure("InsertMultiPart", 1, "desc", 100, 14.5).getResults();
   assertEquals(1, results[0].asScalarLong());
   results = client.callProcedure("SelectMultiPart").getResults();
   System.out.println(results[0].toString());
   assertEquals(1, results[0].getRowCount());
 }
Ejemplo n.º 14
0
  public void test_Interface(
      String[] my_options, String[] my_data, int invalidLineCnt, int validLineCnt)
      throws Exception {
    try {
      BufferedWriter out_csv = new BufferedWriter(new FileWriter(path_csv));
      for (String aMy_data : my_data) {
        out_csv.write(aMy_data + "\n");
      }
      out_csv.flush();
      out_csv.close();
    } catch (Exception e) {
      System.err.print(e.getMessage());
    }

    CSVLoader.testMode = true;
    CSVLoader.main(my_options);
    // do the test

    VoltTable modCount;
    modCount = client.callProcedure("@AdHoc", "SELECT * FROM BLAH;").getResults()[0];
    System.out.println("data inserted to table BLAH:\n" + modCount);
    int rowct = modCount.getRowCount();

    // Call validate partitioning to check if we are good.
    VoltTable valTable;
    valTable = client.callProcedure("@ValidatePartitioning", null, null).getResults()[0];
    System.out.println("Validate for BLAH:\n" + valTable);
    while (valTable.advanceRow()) {
      long miscnt = valTable.getLong("MISPARTITIONED_ROWS");
      assertEquals(miscnt, 0);
    }

    BufferedReader csvreport = new BufferedReader(new FileReader(CSVLoader.pathReportfile));
    int lineCount = 0;
    String line;
    String promptMsg = "Number of rows successfully inserted:";
    String promptFailMsg = "Number of rows that could not be inserted:";
    int invalidlinecnt = 0;

    while ((line = csvreport.readLine()) != null) {
      if (line.startsWith(promptMsg)) {
        String num = line.substring(promptMsg.length());
        lineCount = Integer.parseInt(num.replaceAll("\\s", ""));
      }
      if (line.startsWith(promptFailMsg)) {
        String num = line.substring(promptFailMsg.length());
        invalidlinecnt = Integer.parseInt(num.replaceAll("\\s", ""));
      }
    }
    csvreport.close();
    System.out.println(String.format("The rows infected: (%d,%s)", lineCount, rowct));
    assertEquals(lineCount, rowct);
    // assert validLineCnt specified equals the successfully inserted lineCount
    assertEquals(validLineCnt, lineCount);
    assertEquals(invalidLineCnt, invalidlinecnt);
  }
Ejemplo n.º 15
0
  public void testRejoinInlineStringBug() throws Exception {
    VoltProjectBuilder builder = getBuilderForTest();

    LocalCluster cluster =
        new LocalCluster("rejoin.jar", 1, 2, 1, BackendTarget.NATIVE_EE_JNI, true);
    boolean success = cluster.compile(builder);
    assertTrue(success);
    MiscUtils.copyFile(
        builder.getPathToDeployment(), Configuration.getPathToCatalogForTest("rejoin.xml"));
    cluster.setHasLocalServer(false);

    cluster.startUp();
    Client client;

    client = ClientFactory.createClient(m_cconfig);
    client.createConnection("localhost");

    ProcedureCallback callback =
        new ProcedureCallback() {

          @Override
          public void clientCallback(ClientResponse clientResponse) throws Exception {
            if (clientResponse.getStatus() != ClientResponse.SUCCESS) {
              System.out.println(clientResponse.getStatusString());
            }
          }
        };

    StringBuffer shortBuffer = new StringBuffer();
    for (int ii = 0; ii < 33; ii++) {
      shortBuffer.append('a');
    }
    String shortString = shortBuffer.toString();

    StringBuffer longBuffer = new StringBuffer();
    for (int ii = 0; ii < 17700; ii++) {
      longBuffer.append('a');
    }
    String longString = longBuffer.toString();

    for (int ii = 0; ii < 119; ii++) {
      client.callProcedure(callback, "InsertInlinedString", ii, shortString, longString);
    }

    shortBuffer.append("aaa");
    client.callProcedure(callback, "InsertInlinedString", 120, shortBuffer.toString(), longString);

    client.drain();
    client.close();

    cluster.shutDownSingleHost(0);
    cluster.recoverOne(0, 1, "localhost");

    cluster.shutDown();
  }
Ejemplo n.º 16
0
  private void initUniqueTableExtra(Client client, boolean append)
      throws NoConnectionsException, IOException, ProcCallException {
    if (!append) {
      initUniqueTable(client);
    }

    // extra data
    client.callProcedure("tu.insert", 60, 2);
    client.callProcedure("tu.insert", 70, 3);
    client.callProcedure("tu.insert", 80, 2);
  }
Ejemplo n.º 17
0
  public void testInitiatorStatistics() throws Exception {
    System.out.println("\n\nTESTING INITIATOR STATS\n\n\n");
    Client client = getFullyConnectedClient();

    ColumnInfo[] expectedSchema = new ColumnInfo[13];
    expectedSchema[0] = new ColumnInfo("TIMESTAMP", VoltType.BIGINT);
    expectedSchema[1] = new ColumnInfo("HOST_ID", VoltType.INTEGER);
    expectedSchema[2] = new ColumnInfo("HOSTNAME", VoltType.STRING);
    expectedSchema[3] = new ColumnInfo("SITE_ID", VoltType.INTEGER);
    expectedSchema[4] = new ColumnInfo("CONNECTION_ID", VoltType.BIGINT);
    expectedSchema[5] = new ColumnInfo("CONNECTION_HOSTNAME", VoltType.STRING);
    expectedSchema[6] = new ColumnInfo("PROCEDURE_NAME", VoltType.STRING);
    expectedSchema[7] = new ColumnInfo("INVOCATIONS", VoltType.BIGINT);
    expectedSchema[8] = new ColumnInfo("AVG_EXECUTION_TIME", VoltType.INTEGER);
    expectedSchema[9] = new ColumnInfo("MIN_EXECUTION_TIME", VoltType.INTEGER);
    expectedSchema[10] = new ColumnInfo("MAX_EXECUTION_TIME", VoltType.INTEGER);
    expectedSchema[11] = new ColumnInfo("ABORTS", VoltType.BIGINT);
    expectedSchema[12] = new ColumnInfo("FAILURES", VoltType.BIGINT);
    VoltTable expectedTable = new VoltTable(expectedSchema);

    //
    // initiator selector
    //
    VoltTable results[] = null;
    // This should get us an invocation at each host
    for (int i = 0; i < 1000; i++) {
      results = client.callProcedure("NEW_ORDER.insert", i).getResults();
    }
    results = client.callProcedure("@Statistics", "INITIATOR", 0).getResults();
    // one aggregate table returned
    assertEquals(1, results.length);
    System.out.println("Test initiators table: " + results[0].toString());
    // Check the schema
    validateSchema(results[0], expectedTable);
    // One WAREHOUSE.select row per host
    assertEquals(HOSTS, results[0].getRowCount());

    // Verify the invocation counts
    int counts = 0;
    while (results[0].advanceRow()) {
      String procName = results[0].getString("PROCEDURE_NAME");
      if (procName.equals("@SystemCatalog")) {
        // One for each connection from the client
        assertEquals(HOSTS, results[0].getLong("INVOCATIONS"));
      } else if (procName.equals("NEW_ORDER.insert")) {
        counts += results[0].getLong("INVOCATIONS");
      }
    }
    assertEquals(1000, counts);
    // verify that each node saw a NEW_ORDER.insert initiation
    Map<String, String> columnTargets = new HashMap<String, String>();
    columnTargets.put("PROCEDURE_NAME", "NEW_ORDER.insert");
    validateRowSeenAtAllHosts(results[0], columnTargets, true);
  }
Ejemplo n.º 18
0
 public void testDistinct() throws IOException, ProcCallException {
   String[] tables = {"P1", "R1"};
   for (String table : tables) {
     Client client = getClient();
     for (int i = 0; i < ROWS; ++i) {
       client.callProcedure("Insert", table, i, "desc", new BigDecimal(10.0), i / 2, 14.5);
     }
     String query = String.format("select distinct %s.NUM from %s", table, table);
     VoltTable[] results = client.callProcedure("@AdHoc", query).getResults();
     // lazy check that we get 5 rows back, put off checking contents
     assertEquals(5, results[0].getRowCount());
   }
 }
Ejemplo n.º 19
0
  public void testAggregatesWithNulls() throws IOException, ProcCallException {
    int good_rows = 10;
    int null_rows = 5;

    String[] aggs = {"sum", "min", "max", "avg"};
    long[] expected_int_results = {(0 + 1 + 2 + 3 + 4) * 2, 0, 4, 2};
    double[] expected_float_results = {
      (0 + 0.5 + 1 + 1.5 + 2 + 2.5 + 3 + 3.5 + 4 + 4.5), 0.0, 4.5, 2.25
    };
    String[] tables = {"P1", "R1"};
    for (String table : tables) {
      Client client = getClient();
      for (int i = 0; i < good_rows; ++i) {
        client.callProcedure("Insert", table, i, "desc", new BigDecimal(i / 2.0), i / 2, i / 2.0);
      }
      for (int i = good_rows; i < good_rows + null_rows; ++i) {
        client.callProcedure(
            "Insert",
            table,
            i,
            VoltType.NULL_STRING,
            VoltType.NULL_DECIMAL,
            VoltType.NULL_INTEGER,
            VoltType.NULL_FLOAT);
      }
      // do count separately since it's always integer return type
      String query = String.format("select count(%s.CASH) from %s", table, table);
      VoltTable[] results = client.callProcedure("@AdHoc", query).getResults();
      assertEquals(good_rows, results[0].asScalarLong());
      query = String.format("select count(%s.NUM) from %s", table, table);
      results = client.callProcedure("@AdHoc", query).getResults();
      assertEquals(good_rows, results[0].asScalarLong());
      query = String.format("select count(%s.RATIO) from %s", table, table);
      results = client.callProcedure("@AdHoc", query).getResults();
      assertEquals(good_rows, results[0].asScalarLong());
      for (int i = 0; i < aggs.length; ++i) {
        query = String.format("select %s(%s.CASH) from %s", aggs[i], table, table);
        results = client.callProcedure("@AdHoc", query).getResults();
        results[0].advanceRow();
        assertEquals(expected_float_results[i], results[0].getDecimalAsBigDecimal(0).doubleValue());
        query = String.format("select %s(%s.NUM) from %s", aggs[i], table, table);
        results = client.callProcedure("@AdHoc", query).getResults();
        assertEquals(expected_int_results[i], results[0].asScalarLong());
        query = String.format("select %s(%s.RATIO) from %s", aggs[i], table, table);
        results = client.callProcedure("@AdHoc", query).getResults();
        results[0].advanceRow();
        assertEquals(expected_float_results[i], results[0].getDouble(0));
      }
      // and finish up with count(*) for good measure
      query = String.format("select count(*) from %s", table);
      results = client.callProcedure("@AdHoc", query).getResults();
      results[0].advanceRow();
      assertEquals(good_rows + null_rows, results[0].asScalarLong());
    }
  }
Ejemplo n.º 20
0
  public void testThreeColumnsUniqueIndex() throws Exception {
    Client client = getClient();
    client.callProcedure("TU4.insert", 1, 1, "xin", 0);
    client.callProcedure("TU4.insert", 2, 2, "xin", 1);
    client.callProcedure("TU4.insert", 3, 3, "xin", 0);
    client.callProcedure("TU4.insert", 4, 6, "xin", 1);
    client.callProcedure("TU4.insert", 5, 8, "xin", 0);
    client.callProcedure("TU4.insert", 6, 1, "jia", 0);
    client.callProcedure("TU4.insert", 7, 2, "jia", 1);
    client.callProcedure("TU4.insert", 8, 3, "jia", 0);
    client.callProcedure("TU4.insert", 9, 6, "jia", 1);
    client.callProcedure("TU4.insert", 10, 8, "jia", 0);

    VoltTable table;
    // test with 2,6
    table =
        client.callProcedure(
                "@AdHoc", "SELECT COUNT(*) FROM TU4 WHERE UNAME = 'xin' AND SEX = 0 AND POINTS < 6")
            .getResults()[0];
    assertTrue(table.getRowCount() == 1);
    assertTrue(table.advanceRow());
    assertEquals(2, table.getLong(0));

    table =
        client.callProcedure(
                "@AdHoc",
                "SELECT COUNT(*) FROM TU4 WHERE UNAME = 'xin' AND SEX = 0 AND POINTS >= 2 AND POINTS < 6")
            .getResults()[0];
    assertTrue(table.getRowCount() == 1);
    assertTrue(table.advanceRow());
    assertEquals(1, table.getLong(0));
  }
Ejemplo n.º 21
0
  @Override
  public int scan(
      String keyspace,
      String lowerBound,
      int recordCount,
      Set<String> columns,
      Vector<HashMap<String, ByteIterator>> result) {
    try {
      byte[] ks = keyspace.getBytes(UTF8);
      ClientResponse response =
          m_client.callProcedure("Scan", ks, lowerBound, lowerBound.getBytes(UTF8), recordCount);
      if (response.getStatus() != ClientResponse.SUCCESS) {
        return 1;
      }

      int nFound = 0;
      String partKey = lowerBound;
      CyclicBarrier barrier = new CyclicBarrier(2);
      result.ensureCapacity(recordCount);
      ScanCallback callback = null;
      boolean proceed = true;
      while (proceed) {
        if (response.getStatus() != ClientResponse.SUCCESS) {
          return 1;
        }
        VoltTable table = response.getResults()[0];
        nFound += table.getRowCount();
        proceed = nFound < recordCount && (partKey = nextPartitionKey(partKey)) != null;
        if (proceed) {
          barrier.reset();
          callback = new ScanCallback(barrier);
          m_client.callProcedure(callback, "Scan", ks, partKey, null, recordCount - nFound);
        }

        while (table.advanceRow()) {
          result.add(unpackRowData(table, columns));
        }

        if (proceed) {
          barrier.await();
          response = callback.response;
        }
      }
      return 0;
    } catch (Exception e) {
      e.printStackTrace();
      return 1;
    }
  }
  public void testNonIndexHittingUpdates() throws Exception {
    final Client client = this.getClient();
    ClientResponse response;
    VoltTable table;

    response = client.callProcedure("InsertT1", "a", "b", "c");
    assertEquals(1, getLongFromResponse(response));

    response = client.callProcedure("UpdateT1c", "c2", "a");
    assertEquals(1, getLongFromResponse(response));

    response = client.callProcedure("LookupT1b", "b");
    table = getSingleRowTable(response);
    System.out.println(table.toJSONString());
  }
 // verify correct behavior on invalid command
 public void testProfCtlInvalidCommand() throws Exception {
   Client client = getClient();
   ClientResponse resp = client.callProcedure("@ProfCtl", "MakeAPony");
   @SuppressWarnings("unused")
   VoltTable vt = resp.getResults()[0];
   assertTrue(true);
 }
Ejemplo n.º 24
0
  public void testRejoinSysprocButFail() throws Exception {
    VoltProjectBuilder builder = getBuilderForTest();
    boolean success = builder.compile(Configuration.getPathToCatalogForTest("rejoin.jar"), 1, 1, 0);
    assertTrue(success);
    MiscUtils.copyFile(
        builder.getPathToDeployment(), Configuration.getPathToCatalogForTest("rejoin.xml"));

    VoltDB.Configuration config = new VoltDB.Configuration();
    config.m_pathToCatalog = Configuration.getPathToCatalogForTest("rejoin.jar");
    config.m_pathToDeployment = Configuration.getPathToCatalogForTest("rejoin.xml");
    config.m_isRejoinTest = true;
    ServerThread localServer = new ServerThread(config);

    localServer.start();
    localServer.waitForInitialization();

    Client client = ClientFactory.createClient();
    client.createConnection("localhost");

    SyncCallback scb = new SyncCallback();
    success = false;
    while (!success) {
      success = client.callProcedure(scb, "@Rejoin", "localhost", config.m_internalPort + 1);
      if (!success) Thread.sleep(100);
    }

    scb.waitForResponse();
    ClientResponse response = scb.getResponse();
    assertTrue(response.getStatusString().contains("Unable to find down node"));

    client.close();
    localServer.shutdown();
    localServer.join();
  }
Ejemplo n.º 25
0
  @Override
  public void run() {
    byte[] data = new byte[rowSize];
    r.nextBytes(data);

    try {
      long currentRowCount = getRowCount();
      while ((currentRowCount < targetCount) && (m_shouldContinue.get())) {
        CountDownLatch latch = new CountDownLatch(batchSize);
        // try to insert batchSize random rows
        for (int i = 0; i < batchSize; i++) {
          long p = Math.abs(r.nextLong());
          m_permits.acquire();
          client.callProcedure(
              new InsertCallback(latch), tableName.toUpperCase() + "TableInsert", p, data);
        }
        latch.await(10, TimeUnit.SECONDS);
        long nextRowCount = getRowCount();
        // if no progress, throttle a bit
        if (nextRowCount == currentRowCount) {
          Thread.sleep(1000);
        }
        currentRowCount = nextRowCount;
      }

    } catch (Exception e) {
      // on exception, log and end the thread, but don't kill the process
      log.error(
          "BigTableLoader failed a procedure call for table "
              + tableName
              + " and the thread will now stop.",
          e);
      return;
    }
  }
Ejemplo n.º 26
0
  protected static void verifyProcFails(
      Client client, String expectedPattern, String storedProc, Object... args) throws IOException {

    String what;
    if (storedProc.compareTo("@AdHoc") == 0) {
      what = "the statement \"" + args[0] + "\"";
    } else {
      what = "the stored procedure \"" + storedProc + "\"";
    }

    try {
      client.callProcedure(storedProc, args);
    } catch (ProcCallException pce) {
      String msg = pce.getMessage();
      String diagnostic =
          "Expected "
              + what
              + " to throw an exception matching the pattern \""
              + expectedPattern
              + "\", but instead it threw an exception containing \""
              + msg
              + "\".";
      Pattern pattern = Pattern.compile(expectedPattern, Pattern.MULTILINE);
      assertTrue(diagnostic, pattern.matcher(msg).find());
      return;
    }

    String diagnostic =
        "Expected "
            + what
            + " to throw an exception matching the pattern \""
            + expectedPattern
            + "\", but instead it threw nothing.";
    fail(diagnostic);
  }
Ejemplo n.º 27
0
  /**
   * add 20 shuffled rows
   *
   * @throws InterruptedException
   */
  private void load(Client client)
      throws NoConnectionsException, ProcCallException, IOException, InterruptedException {
    int pkey = 0;
    a_int.clear();
    a_inline_str.clear();
    a_pool_str.clear();

    boolean async = true;

    for (int i = 0; i < 20; i++) {
      a_int.add(i);
      a_inline_str.add("a_" + i);
      a_pool_str.add(simpleString + i);
    }

    Collections.shuffle(a_int);
    Collections.shuffle(a_inline_str);
    Collections.shuffle(a_pool_str);

    for (int i = 0; i < 20; i++) {
      SyncCallback cb = new SyncCallback();
      client.callProcedure(
          cb, "InsertO1", pkey, a_int.get(i), a_inline_str.get(i), a_pool_str.get(i));

      if (!async) {
        cb.waitForResponse();
        VoltTable vt = cb.getResponse().getResults()[0];
        assertTrue(vt.getRowCount() == 1);
      }
      pkey = pkey + 1;
    }

    client.drain();
  }
Ejemplo n.º 28
0
  public void testStarvationStatistics() throws Exception {
    System.out.println("\n\nTESTING STARVATION STATS\n\n\n");
    Client client = getFullyConnectedClient();

    ColumnInfo[] expectedSchema = new ColumnInfo[10];
    expectedSchema[0] = new ColumnInfo("TIMESTAMP", VoltType.BIGINT);
    expectedSchema[1] = new ColumnInfo("HOST_ID", VoltType.INTEGER);
    expectedSchema[2] = new ColumnInfo("HOSTNAME", VoltType.STRING);
    expectedSchema[3] = new ColumnInfo("SITE_ID", VoltType.INTEGER);
    expectedSchema[4] = new ColumnInfo("COUNT", VoltType.BIGINT);
    expectedSchema[5] = new ColumnInfo("PERCENT", VoltType.FLOAT);
    expectedSchema[6] = new ColumnInfo("AVG", VoltType.BIGINT);
    expectedSchema[7] = new ColumnInfo("MIN", VoltType.BIGINT);
    expectedSchema[8] = new ColumnInfo("MAX", VoltType.BIGINT);
    expectedSchema[9] = new ColumnInfo("STDDEV", VoltType.BIGINT);
    VoltTable expectedTable = new VoltTable(expectedSchema);

    VoltTable[] results = null;
    //
    // STARVATION
    //
    results = client.callProcedure("@Statistics", "STARVATION", 0).getResults();
    // one aggregate table returned
    assertEquals(1, results.length);
    System.out.println("Test STARVATION table: " + results[0].toString());
    validateSchema(results[0], expectedTable);
    // One row per site, we don't use HSID though, so hard to do straightforward
    // per-site unique check.  Finesse it.
    // We also get starvation stats for the MPI, so we need to add a site per host.
    assertEquals(HOSTS * (SITES + 1), results[0].getRowCount());
    results[0].advanceRow();
    Map<String, String> columnTargets = new HashMap<String, String>();
    columnTargets.put("HOSTNAME", results[0].getString("HOSTNAME"));
    validateRowSeenAtAllHosts(results[0], columnTargets, false);
  }
Ejemplo n.º 29
0
  public void testIOStatistics() throws Exception {
    System.out.println("\n\nTESTING IO STATS\n\n\n");
    Client client = getFullyConnectedClient();

    // Based on doc, not code
    // HOST_ID, SITE_ID, and PARTITION_ID all differ.  Fixed to match
    // reality so tests would pass, but, ugh.
    ColumnInfo[] expectedSchema = new ColumnInfo[9];
    expectedSchema[0] = new ColumnInfo("TIMESTAMP", VoltType.BIGINT);
    expectedSchema[1] = new ColumnInfo("HOST_ID", VoltType.INTEGER);
    expectedSchema[2] = new ColumnInfo("HOSTNAME", VoltType.STRING);
    expectedSchema[3] = new ColumnInfo("CONNECTION_ID", VoltType.BIGINT);
    expectedSchema[4] = new ColumnInfo("CONNECTION_HOSTNAME", VoltType.STRING);
    expectedSchema[5] = new ColumnInfo("BYTES_READ", VoltType.BIGINT);
    expectedSchema[6] = new ColumnInfo("MESSAGES_READ", VoltType.BIGINT);
    expectedSchema[7] = new ColumnInfo("BYTES_WRITTEN", VoltType.BIGINT);
    expectedSchema[8] = new ColumnInfo("MESSAGES_WRITTEN", VoltType.BIGINT);
    VoltTable expectedTable = new VoltTable(expectedSchema);

    VoltTable[] results = null;
    //
    // iostats
    //
    results = client.callProcedure("@Statistics", "iostats", 0).getResults();
    System.out.println("Test iostats table: " + results[0].toString());
    // one aggregate table returned
    assertEquals(1, results.length);
    validateSchema(results[0], expectedTable);
  }
 // Pretty lame test but at least invoke the procedure.
 // "@Quiesce" is used more meaningfully in TestExportSuite.
 public void testQuiesce() throws IOException, ProcCallException {
   Client client = getClient();
   VoltTable results[] = client.callProcedure("@Quiesce").getResults();
   assertEquals(1, results.length);
   results[0].advanceRow();
   assertEquals(results[0].get(0, VoltType.BIGINT), new Long(0));
 }