use of com.datastax.driver.core.BatchStatement in project cassandra by apache.
the class BatchTests method testOversizedBatch.
@Test(expected = InvalidQueryException.class)
public void testOversizedBatch() {
int SIZE_FOR_FAILURE = 2500;
BatchStatement b = new BatchStatement(BatchStatement.Type.UNLOGGED);
for (int i = 0; i < SIZE_FOR_FAILURE; i++) {
b.add(noncounter.bind(i, "foobar"));
}
session.execute(b);
}
use of com.datastax.driver.core.BatchStatement in project cassandra by apache.
the class BatchTests method sendBatch.
public void sendBatch(BatchStatement.Type type, boolean addCounter, boolean addNonCounter, boolean addClustering) {
assert addCounter || addNonCounter || addClustering;
BatchStatement b = new BatchStatement(type);
for (int i = 0; i < 10; i++) {
if (addNonCounter)
b.add(noncounter.bind(i, "foo"));
if (addCounter)
b.add(counter.bind((long) i, i));
if (addClustering) {
b.add(clustering.bind(i, i, i, i, "foo"));
}
}
session.execute(b);
}
use of com.datastax.driver.core.BatchStatement in project cassandra by apache.
the class AuditLoggerTest method testCqlBatch_MultipleTablesAuditing.
@Test
public void testCqlBatch_MultipleTablesAuditing() {
createTable("CREATE TABLE %s (id int primary key, v1 text, v2 text)");
String table1 = currentTable();
Session session = sessionNet();
BatchStatement batchStatement = new BatchStatement();
String cqlInsert1 = "INSERT INTO " + KEYSPACE + "." + table1 + " (id, v1, v2) VALUES (?, ?, ?)";
PreparedStatement prep = session.prepare(cqlInsert1);
AuditLogEntry logEntry = ((InMemoryAuditLogger) AuditLogManager.instance.getLogger()).inMemQueue.poll();
assertLogEntry(cqlInsert1, AuditLogEntryType.PREPARE_STATEMENT, logEntry, false);
batchStatement.add(prep.bind(1, "Apapche", "Cassandra"));
createTable("CREATE TABLE %s (id int primary key, v1 text, v2 text)");
String table2 = currentTable();
String cqlInsert2 = "INSERT INTO " + KEYSPACE + "." + table2 + " (id, v1, v2) VALUES (?, ?, ?)";
prep = session.prepare(cqlInsert2);
logEntry = ((InMemoryAuditLogger) AuditLogManager.instance.getLogger()).inMemQueue.poll();
assertLogEntry(cqlInsert2, AuditLogEntryType.PREPARE_STATEMENT, logEntry, false);
batchStatement.add(prep.bind(1, "Apapche", "Cassandra"));
createKeyspace("CREATE KEYSPACE %s WITH replication={ 'class' : 'SimpleStrategy', 'replication_factor' : 1 }");
String ks2 = currentKeyspace();
createTable(ks2, "CREATE TABLE %s (id int primary key, v1 text, v2 text)");
String table3 = currentTable();
String cqlInsert3 = "INSERT INTO " + ks2 + "." + table3 + " (id, v1, v2) VALUES (?, ?, ?)";
prep = session.prepare(cqlInsert3);
logEntry = ((InMemoryAuditLogger) AuditLogManager.instance.getLogger()).inMemQueue.poll();
assertLogEntry(cqlInsert3, AuditLogEntryType.PREPARE_STATEMENT, logEntry, false, ks2);
batchStatement.add(prep.bind(1, "Apapche", "Cassandra"));
ResultSet rs = session.execute(batchStatement);
assertEquals(4, ((InMemoryAuditLogger) AuditLogManager.instance.getLogger()).inMemQueue.size());
logEntry = ((InMemoryAuditLogger) AuditLogManager.instance.getLogger()).inMemQueue.poll();
logEntry = ((InMemoryAuditLogger) AuditLogManager.instance.getLogger()).inMemQueue.poll();
assertLogEntry(cqlInsert1, table1, AuditLogEntryType.UPDATE, logEntry, false, KEYSPACE);
logEntry = ((InMemoryAuditLogger) AuditLogManager.instance.getLogger()).inMemQueue.poll();
assertLogEntry(cqlInsert2, table2, AuditLogEntryType.UPDATE, logEntry, false, KEYSPACE);
logEntry = ((InMemoryAuditLogger) AuditLogManager.instance.getLogger()).inMemQueue.poll();
assertLogEntry(cqlInsert3, table3, AuditLogEntryType.UPDATE, logEntry, false, ks2);
int size = rs.all().size();
assertEquals(0, size);
}
use of com.datastax.driver.core.BatchStatement in project cassandra by apache.
the class TableMetricsTest method executeBatch.
private void executeBatch(boolean isLogged, int distinctPartitions, int statementsPerPartition, String... tables) {
if (tables == null || tables.length == 0) {
tables = new String[] { TABLE };
}
BatchStatement.Type batchType;
if (isLogged) {
batchType = BatchStatement.Type.LOGGED;
} else {
batchType = BatchStatement.Type.UNLOGGED;
}
BatchStatement batch = new BatchStatement(batchType);
for (String table : tables) populateBatch(batch, table, distinctPartitions, statementsPerPartition);
session.execute(batch);
}
use of com.datastax.driver.core.BatchStatement in project storm by apache.
the class CassandraState method updateState.
public void updateState(List<TridentTuple> tuples, final TridentCollector collector) {
List<Statement> statements = new ArrayList<>();
for (TridentTuple tuple : tuples) {
statements.addAll(options.cqlStatementTupleMapper.map(conf, session, tuple));
}
try {
if (options.batchingType != null) {
BatchStatement batchStatement = new BatchStatement(options.batchingType);
batchStatement.addAll(statements);
session.execute(batchStatement);
} else {
for (Statement statement : statements) {
session.execute(statement);
}
}
} catch (Exception e) {
LOG.warn("Batch write operation is failed.");
collector.reportError(e);
throw new FailedException(e);
}
}
Aggregations