public void run(final SimpleClient client) throws IOException { run(new CQLQueryExecutor() { public boolean execute(String cqlQuery, List<String> queryParams) throws Exception { ResultMessage result = null; if (session.usePreparedStatements()) { byte[] stmntId = getPreparedStatement(client, cqlQuery); result = client.executePrepared(stmntId, queryParamsAsByteBuffer(queryParams), ThriftConversion.fromThrift(session.getConsistencyLevel())); } else { String formattedQuery = formatCqlQuery(cqlQuery, queryParams); result = client.execute(formattedQuery, ThriftConversion.fromThrift(session.getConsistencyLevel())); } return validateNativeResult(result); } }); }
public List<ValidatingSchemaQuery> getValidate(Timer timer, PartitionGenerator generator, SeedManager seedManager, StressSettings settings) { if (validationFactories == null) { synchronized (this) { if (validationFactories == null) { maybeLoadSchemaInfo(settings); validationFactories = ValidatingSchemaQuery.create(tableMetaData, settings); } } } List<ValidatingSchemaQuery> queries = new ArrayList<>(); for (ValidatingSchemaQuery.Factory factory : validationFactories) queries.add(factory.create(timer, settings, generator, seedManager, ThriftConversion.fromThrift(settings.command.consistencyLevel))); return queries; }
@Test // test for CASSANDRA-8178 public void testNonTextComparator() throws Throwable { ColumnDef column = new ColumnDef(); column.setName(bytes(42)) .setValidation_class(UTF8Type.instance.toString()); CfDef cf = new CfDef("thriftcompat", "JdbcInteger"); cf.setColumn_type("Standard") .setComparator_type(Int32Type.instance.toString()) .setDefault_validation_class(UTF8Type.instance.toString()) .setKey_validation_class(BytesType.instance.toString()) .setColumn_metadata(Collections.singletonList(column)); SchemaLoader.createKeyspace("thriftcompat", KeyspaceParams.simple(1), ThriftConversion.fromThrift(cf)); // the comparator is IntegerType, and there is a column named 42 with a UTF8Type validation type execute("INSERT INTO \"thriftcompat\".\"JdbcInteger\" (key, \"42\") VALUES (0x00000001, 'abc')"); execute("UPDATE \"thriftcompat\".\"JdbcInteger\" SET \"42\" = 'abc' WHERE key = 0x00000001"); execute("DELETE \"42\" FROM \"thriftcompat\".\"JdbcInteger\" WHERE key = 0x00000000"); UntypedResultSet results = execute("SELECT key, \"42\" FROM \"thriftcompat\".\"JdbcInteger\""); assertEquals(1, results.size()); UntypedResultSet.Row row = results.iterator().next(); assertEquals(ByteBufferUtil.bytes(1), row.getBytes("key")); assertEquals("abc", row.getString("42")); }
@Override public <V> V execute(Object preparedStatementId, ByteBuffer key, List<Object> queryParams, ResultHandler<V> handler) { return handler.javaDriverHandler().apply( client.executePrepared( (PreparedStatement) preparedStatementId, queryParams, ThriftConversion.fromThrift(settings.command.consistencyLevel))); }
@Override public <V> V execute(Object preparedStatementId, ByteBuffer key, List<Object> queryParams, ResultHandler<V> handler) { return handler.thriftHandler().apply( client.executePrepared( (byte[]) preparedStatementId, toByteBufferParams(queryParams), ThriftConversion.fromThrift(settings.command.consistencyLevel))); }
public boolean run() throws Exception { CqlResult rs = client.execute_prepared_cql3_query(thriftId, partitions.get(0).getToken(), thriftArgs(), ThriftConversion.toThrift(cl)); validate(rs); rowCount = rs.getRowsSize(); partitionCount = Math.min(1, rowCount); return true; }
public boolean run() throws Exception { CqlResult rs = client.execute_prepared_cql3_query(thriftId, partitions.get(0).getToken(), thriftArgs(), ThriftConversion.toThrift(cl)); rowCount = rs.getRowsSize(); partitionCount = Math.min(1, rowCount); return true; }
@Test // test for CASSANDRA-9867 public void testDropCompactStaticColumn() { ColumnDef column1 = new ColumnDef(); column1.setName(bytes(42)) .setValidation_class(UTF8Type.instance.toString()); ColumnDef column2 = new ColumnDef(); column2.setName(bytes(25)) .setValidation_class(UTF8Type.instance.toString()); CfDef cf = new CfDef("thriftks", "staticcompact"); cf.setColumn_type("Standard") .setComparator_type(Int32Type.instance.toString()) .setDefault_validation_class(UTF8Type.instance.toString()) .setKey_validation_class(BytesType.instance.toString()) .setColumn_metadata(Arrays.asList(column1, column2)); SchemaLoader.createKeyspace("thriftks", KeyspaceParams.simple(1), ThriftConversion.fromThrift(cf)); CFMetaData cfm = Schema.instance.getCFMetaData("thriftks", "staticcompact"); // assert the both columns are in the metadata assertTrue(cfm.getColumnMetadata().containsKey(bytes(42))); assertTrue(cfm.getColumnMetadata().containsKey(bytes(25))); // remove column2 cf.setColumn_metadata(Collections.singletonList(column1)); MigrationManager.announceColumnFamilyUpdate(ThriftConversion.fromThriftForUpdate(cf, cfm), true); // assert that it's gone from metadata assertTrue(cfm.getColumnMetadata().containsKey(bytes(42))); assertFalse(cfm.getColumnMetadata().containsKey(bytes(25))); }
@Test public void testCFMetaDataSerialization() throws ConfigurationException, InvalidRequestException { // test serialization of all defined test CFs. for (String keyspaceName : Schema.instance.getNonSystemKeyspaces()) { for (CFMetaData cfm : Schema.instance.getTablesAndViews(keyspaceName)) { CFMetaData cfmDupe = ThriftConversion.fromThrift(ThriftConversion.toThrift(cfm)); assertNotNull(cfmDupe); assertEquals(cfm, cfmDupe); } } }
@Test public void testKSMetaDataSerialization() throws ConfigurationException { for (String ks : Schema.instance.getNonSystemKeyspaces()) { // Not testing round-trip on the KsDef via serDe() because maps KeyspaceMetadata ksm = Schema.instance.getKSMetaData(ks); KeyspaceMetadata ksmDupe = ThriftConversion.fromThrift(ThriftConversion.toThrift(ksm)); assertNotNull(ksmDupe); assertEquals(ksm, ksmDupe); } }
@Test public void testThriftConversion() throws Exception { CfDef cfDef = new CfDef().setDefault_validation_class(AsciiType.class.getCanonicalName()) .setComment("Test comment") .setColumn_metadata(columnDefs) .setKeyspace(KEYSPACE1) .setName(CF_STANDARD1); // convert Thrift to CFMetaData CFMetaData cfMetaData = ThriftConversion.fromThrift(cfDef); CfDef thriftCfDef = new CfDef(); thriftCfDef.keyspace = KEYSPACE1; thriftCfDef.name = CF_STANDARD1; thriftCfDef.default_validation_class = cfDef.default_validation_class; thriftCfDef.comment = cfDef.comment; thriftCfDef.column_metadata = new ArrayList<>(); for (ColumnDef columnDef : columnDefs) { ColumnDef c = new ColumnDef(); c.name = ByteBufferUtil.clone(columnDef.name); c.validation_class = columnDef.getValidation_class(); c.index_name = columnDef.getIndex_name(); c.index_type = columnDef.getIndex_type(); if (columnDef.isSetIndex_options()) c.setIndex_options(columnDef.getIndex_options()); thriftCfDef.column_metadata.add(c); } CfDef converted = ThriftConversion.toThrift(cfMetaData); assertEquals(thriftCfDef.keyspace, converted.keyspace); assertEquals(thriftCfDef.name, converted.name); assertEquals(thriftCfDef.default_validation_class, converted.default_validation_class); assertEquals(thriftCfDef.comment, converted.comment); assertEquals(new HashSet<>(thriftCfDef.column_metadata), new HashSet<>(converted.column_metadata)); }
protected void testSerializeDeserialize(CFMetaData cfm, ColumnDefinition cd) throws Exception { ColumnDefinition newCd = ThriftConversion.fromThrift(cfm.ksName, cfm.cfName, cfm.comparator.subtype(0), null, ThriftConversion.toThrift(cfm, cd)); Assert.assertNotSame(cd, newCd); Assert.assertEquals(cd.hashCode(), newCd.hashCode()); Assert.assertEquals(cd, newCd); }
@Test public void testThriftConversion() throws Exception { CfDef cfDef = new CfDef().setDefault_validation_class(AsciiType.class.getCanonicalName()) .setComment("Test comment") .setColumn_metadata(columnDefs) .setKeyspace(KEYSPACE1) .setName(CF_STANDARD1); // convert Thrift to CFMetaData CFMetaData cfMetaData = ThriftConversion.fromThrift(cfDef); CfDef thriftCfDef = new CfDef(); thriftCfDef.keyspace = KEYSPACE1; thriftCfDef.name = CF_STANDARD1; thriftCfDef.default_validation_class = cfDef.default_validation_class; thriftCfDef.comment = cfDef.comment; thriftCfDef.column_metadata = new ArrayList<>(); for (ColumnDef columnDef : columnDefs) { ColumnDef c = new ColumnDef(); c.name = ByteBufferUtil.clone(columnDef.name); c.validation_class = columnDef.getValidation_class(); c.index_name = columnDef.getIndex_name(); c.index_type = IndexType.KEYS; thriftCfDef.column_metadata.add(c); } CfDef converted = ThriftConversion.toThrift(cfMetaData); assertEquals(thriftCfDef.keyspace, converted.keyspace); assertEquals(thriftCfDef.name, converted.name); assertEquals(thriftCfDef.default_validation_class, converted.default_validation_class); assertEquals(thriftCfDef.comment, converted.comment); assertEquals(new HashSet<>(thriftCfDef.column_metadata), new HashSet<>(converted.column_metadata)); }
public boolean run() throws Exception { CqlResult rs = client.execute_prepared_cql3_query(thriftId, partitions.get(0).getToken(), thriftArgs(partitions.get(0)), ThriftConversion.toThrift(cl)); validate(rs); rowCount = rs.getRowsSize(); partitionCount = Math.min(1, rowCount); return true; }
@Override public <V> V execute(Object preparedStatementId, ByteBuffer key, List<ByteBuffer> queryParams, ResultHandler<V> handler) { return handler.javaDriverHandler().apply( client.executePrepared( (PreparedStatement) preparedStatementId, queryParams, ThriftConversion.fromThrift(state.settings.command.consistencyLevel))); }
@Override public <V> V execute(Object preparedStatementId, ByteBuffer key, List<ByteBuffer> queryParams, ResultHandler<V> handler) { return handler.thriftHandler().apply( client.executePrepared( (byte[]) preparedStatementId, queryParams, ThriftConversion.fromThrift(state.settings.command.consistencyLevel))); }
@Override public <V> V execute(Object preparedStatementId, ByteBuffer key, List<Object> queryParams, ResultHandler<V> handler) { return handler.javaDriverHandler().apply( client.executePrepared( (PreparedStatement) preparedStatementId, queryParams, ThriftConversion.fromThrift(state.settings.command.consistencyLevel))); }
@Override public <V> V execute(Object preparedStatementId, ByteBuffer key, List<Object> queryParams, ResultHandler<V> handler) { return handler.thriftHandler().apply( client.executePrepared( (byte[]) preparedStatementId, toByteBufferParams(queryParams), ThriftConversion.fromThrift(state.settings.command.consistencyLevel))); }
@Override public <V> V execute(String query, ByteBuffer key, List<Object> queryParams, ResultHandler<V> handler) { String formattedQuery = formatCqlQuery(query, queryParams, isCql3()); return handler.javaDriverHandler().apply(client.execute(formattedQuery, ThriftConversion.fromThrift(settings.command.consistencyLevel))); }
@Override public <V> V execute(String query, ByteBuffer key, List<Object> queryParams, ResultHandler<V> handler) { String formattedQuery = formatCqlQuery(query, queryParams, isCql3()); return handler.thriftHandler().apply(client.execute(formattedQuery, ThriftConversion.fromThrift(settings.command.consistencyLevel))); }
@Override public <V> V execute(String query, ByteBuffer key, List<Object> queryParams, ResultHandler<V> handler) { String formattedQuery = formatCqlQuery(query, queryParams); return handler.javaDriverHandler().apply(client.execute(formattedQuery, ThriftConversion.fromThrift(settings.command.consistencyLevel))); }
@Override public <V> V execute(String query, ByteBuffer key, List<Object> queryParams, ResultHandler<V> handler) { String formattedQuery = formatCqlQuery(query, queryParams); return handler.thriftHandler().apply(client.execute(formattedQuery, ThriftConversion.fromThrift(settings.command.consistencyLevel))); }
@Override public <V> V execute(String query, ByteBuffer key, List<ByteBuffer> queryParams, ResultHandler<V> handler) { String formattedQuery = formatCqlQuery(query, queryParams, state.isCql3()); return handler.javaDriverHandler().apply(client.execute(formattedQuery, ThriftConversion.fromThrift(state.settings.command.consistencyLevel))); }
@Override public <V> V execute(String query, ByteBuffer key, List<ByteBuffer> queryParams, ResultHandler<V> handler) { String formattedQuery = formatCqlQuery(query, queryParams, state.isCql3()); return handler.thriftHandler().apply(client.execute(formattedQuery, ThriftConversion.fromThrift(state.settings.command.consistencyLevel))); }
@Override public <V> V execute(String query, ByteBuffer key, List<Object> queryParams, ResultHandler<V> handler) { String formattedQuery = formatCqlQuery(query, queryParams); return handler.javaDriverHandler().apply(client.execute(formattedQuery, ThriftConversion.fromThrift(state.settings.command.consistencyLevel))); }
@Override public <V> V execute(String query, ByteBuffer key, List<Object> queryParams, ResultHandler<V> handler) { String formattedQuery = formatCqlQuery(query, queryParams); return handler.thriftHandler().apply(client.execute(formattedQuery, ThriftConversion.fromThrift(state.settings.command.consistencyLevel))); }