@Test
  public void testManyClusterings() throws Throwable {
    StringBuilder table = new StringBuilder("CREATE TABLE %s (a TEXT");
    StringBuilder cols = new StringBuilder();
    StringBuilder args = new StringBuilder("?");
    List<Object> vals = new ArrayList<>();
    vals.add("a");
    for (int i = 0; i < 40; i++) {
      table.append(", c").append(i).append(" text");
      cols.append(", c").append(i);
      if (ThreadLocalRandom.current().nextBoolean()) vals.add(Integer.toString(i));
      else vals.add("");
      args.append(",?");
    }
    args.append(",?");
    vals.add("value");
    table.append(", v text, PRIMARY KEY ((a)").append(cols).append("))");
    createTable(table.toString());

    execute("INSERT INTO %s (a" + cols + ", v) VALUES (" + args + ")", vals.toArray());
    flush();
    UntypedResultSet.Row row = execute("SELECT * FROM %s").one();
    for (int i = 0; i < row.getColumns().size(); i++)
      Assert.assertEquals(vals.get(i), row.getString(i == 0 ? "a" : i < 41 ? "c" + (i - 1) : "v"));
  }
 /** Test For CASSANDRA-8178 */
 @Test
 public void testNonTextComparator() throws Throwable {
   // the comparator is IntegerType, and there is a column named 42 with a UTF8Type validation type
   execute("INSERT INTO \"Keyspace1\".\"JdbcInteger\" (key, \"42\") VALUES (0x00000001, 'abc')");
   execute("UPDATE \"Keyspace1\".\"JdbcInteger\" SET \"42\" = 'abc' WHERE key = 0x00000001");
   execute("DELETE \"42\" FROM \"Keyspace1\".\"JdbcInteger\" WHERE key = 0x00000000");
   UntypedResultSet results = execute("SELECT key, \"42\" FROM \"Keyspace1\".\"JdbcInteger\"");
   assertEquals(1, results.size());
   UntypedResultSet.Row row = results.iterator().next();
   assertEquals(ByteBufferUtil.bytes(1), row.getBytes("key"));
   assertEquals("abc", row.getString("42"));
 }
예제 #3
0
 private static void checkRow(int rowIndex, UntypedResultSet results, Integer... expectedValues) {
   List<UntypedResultSet.Row> rows = newArrayList(results.iterator());
   UntypedResultSet.Row row = rows.get(rowIndex);
   Iterator<ColumnSpecification> columns = row.getColumns().iterator();
   for (Integer expected : expectedValues) {
     String columnName = columns.next().name.toString();
     int actual = row.getInt(columnName);
     assertEquals(
         String.format(
             "Expected value %d for column %s in row %d, but got %s",
             actual, columnName, rowIndex, expected),
         (long) expected,
         actual);
   }
 }