private static void checkExecuteResultSet(ResultSet rs, String key) { assertTrue(!rs.isExhausted()); Row row = rs.one(); assertTrue(rs.isExhausted()); assertEquals(key, row.getString("k")); assertEquals("foo", row.getString("t")); assertEquals(42, row.getInt("i")); assertEquals(24.03f, row.getFloat("f"), 0.1f); }
@Test public void executeTest() throws Exception { // Simple calls to all versions of the execute/executeAsync methods String key = "execute_test"; ResultSet rs = session.execute(String.format(INSERT_FORMAT, TABLE, key, "foo", 42, 24.03f)); assertTrue(rs.isExhausted()); // execute checkExecuteResultSet(session.execute(String.format(SELECT_ALL_FORMAT, TABLE)), key); checkExecuteResultSet( session.execute( new SimpleStatement(String.format(SELECT_ALL_FORMAT, TABLE)) .setConsistencyLevel(ConsistencyLevel.ONE)), key); // executeAsync checkExecuteResultSet( session.executeAsync(String.format(SELECT_ALL_FORMAT, TABLE)).getUninterruptibly(), key); checkExecuteResultSet( session .executeAsync( new SimpleStatement(String.format(SELECT_ALL_FORMAT, TABLE)) .setConsistencyLevel(ConsistencyLevel.ONE)) .getUninterruptibly(), key); }
/** Test simple statement inserts for all collection data types */ public void collectionInsertTest() throws Throwable { ResultSet rs; for (String execute_string : COLLECTION_INSERT_STATEMENTS) { rs = session.execute(execute_string); assertTrue(rs.isExhausted()); } assertEquals(SAMPLE_COLLECTIONS.size(), 255); assertEquals(COLLECTION_INSERT_STATEMENTS.size(), SAMPLE_COLLECTIONS.size()); }
/** Test simple statement inserts for all primitive data types */ public void primitiveInsertTest() throws Throwable { ResultSet rs; for (String execute_string : PRIMITIVE_INSERT_STATEMENTS) { rs = session.execute(execute_string); assertTrue(rs.isExhausted()); } assertEquals(SAMPLE_DATA.size(), 15); assertEquals(PRIMITIVE_INSERT_STATEMENTS.size(), SAMPLE_DATA.size()); }
@Test public void compressionTest() throws Exception { // Same as executeTest, but with compression enabled cluster .getConfiguration() .getProtocolOptions() .setCompression(ProtocolOptions.Compression.SNAPPY); try { Session compressedSession = cluster.connect(TestUtils.SIMPLE_KEYSPACE); // Simple calls to all versions of the execute/executeAsync methods String key = "execute_compressed_test"; ResultSet rs = compressedSession.execute(String.format(INSERT_FORMAT, TABLE, key, "foo", 42, 24.03f)); assertTrue(rs.isExhausted()); String SELECT_ALL = String.format(SELECT_ALL_FORMAT + " WHERE k = '%s'", TABLE, key); // execute checkExecuteResultSet(compressedSession.execute(SELECT_ALL), key); checkExecuteResultSet( compressedSession.execute( new SimpleStatement(SELECT_ALL).setConsistencyLevel(ConsistencyLevel.ONE)), key); // executeAsync checkExecuteResultSet(compressedSession.executeAsync(SELECT_ALL).getUninterruptibly(), key); checkExecuteResultSet( compressedSession .executeAsync( new SimpleStatement(SELECT_ALL).setConsistencyLevel(ConsistencyLevel.ONE)) .getUninterruptibly(), key); } finally { cluster .getConfiguration() .getProtocolOptions() .setCompression(ProtocolOptions.Compression.NONE); } }
@Test public void executePreparedTest() throws Exception { // Simple calls to all versions of the execute/executeAsync methods for prepared statements // Note: the goal is only to exercice the Session methods, PreparedStatementTest have better // prepared statement tests. String key = "execute_prepared_test"; ResultSet rs = session.execute(String.format(INSERT_FORMAT, TABLE, key, "foo", 42, 24.03f)); assertTrue(rs.isExhausted()); PreparedStatement p = session.prepare(String.format(SELECT_ALL_FORMAT + " WHERE k = ?", TABLE)); BoundStatement bs = p.bind(key); // executePrepared checkExecuteResultSet(session.execute(bs), key); checkExecuteResultSet(session.execute(bs.setConsistencyLevel(ConsistencyLevel.ONE)), key); // executePreparedAsync checkExecuteResultSet(session.executeAsync(bs).getUninterruptibly(), key); checkExecuteResultSet( session.executeAsync(bs.setConsistencyLevel(ConsistencyLevel.ONE)).getUninterruptibly(), key); }