com.datastax.driver.core.ConsistencyLevel Java Examples
The following examples show how to use
com.datastax.driver.core.ConsistencyLevel.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DefaultCommandContext.java From titus-control-plane with Apache License 2.0 | 7 votes |
public static CommandContext newCommandContext(CommandLine commandLine) { List<String> ips = StringExt.splitByComma(commandLine.getOptionValue("H")); int sourcePort = Integer.parseInt(commandLine.getOptionValue("p")); QueryOptions queryOptions = new QueryOptions() .setConsistencyLevel(ConsistencyLevel.LOCAL_QUORUM); Cluster cluster = Cluster.builder() .addContactPoints((String[]) ips.toArray()) .withPort(sourcePort) .withQueryOptions(queryOptions) .build(); return new DefaultCommandContext( commandLine, cluster.newSession(), sourceKeySpace -> cluster.connect('"' + sourceKeySpace + '"'), targetKeySpace -> cluster.connect('"' + targetKeySpace + '"') ) { @Override public void shutdown() { cluster.close(); } }; }
Example #2
Source File: HistoryTable.java From arcusplatform with Apache License 2.0 | 6 votes |
@Inject public DetailedSubsystemTable(@Named(CassandraHistory.NAME) Session session, HistoryAppenderConfig config) { super( CassandraQueryBuilder .insert(TABLE_NAME) .addColumns(Columns.PLACE_ID, Columns.SUBSYSTEM, Columns.TIMESTAMP, Columns.MESSAGE_KEY, Columns.PARAMS, Columns.SUBJECT_ADDRESS) .withTtlSec(TimeUnit.HOURS.toSeconds(config.getDetailedSubsysTtlHours())) .prepare(session), CassandraQueryBuilder .select(TABLE_NAME) .addColumns(Columns.PLACE_ID, Columns.SUBSYSTEM, Columns.TIMESTAMP, Columns.MESSAGE_KEY, Columns.PARAMS, Columns.SUBJECT_ADDRESS) .addWhereColumnEquals(Columns.PLACE_ID) .addWhereColumnEquals(Columns.SUBSYSTEM) .withConsistencyLevel(ConsistencyLevel.LOCAL_ONE) .prepare(session), CassandraQueryBuilder .select(TABLE_NAME) .addColumns(Columns.PLACE_ID, Columns.SUBSYSTEM, Columns.TIMESTAMP, Columns.MESSAGE_KEY, Columns.PARAMS, Columns.SUBJECT_ADDRESS) .where(Columns.PLACE_ID + "= ? AND " + Columns.SUBSYSTEM + " = ? AND " + Columns.TIMESTAMP + " <= ?") .withConsistencyLevel(ConsistencyLevel.LOCAL_ONE) .prepare(session) ); }
Example #3
Source File: HistoryTable.java From arcusplatform with Apache License 2.0 | 6 votes |
@Inject public DetailedAlarmTable(@Named(CassandraHistory.NAME) Session session, HistoryAppenderConfig config) { super( CassandraQueryBuilder .insert(TABLE_NAME) .addColumns(Columns.INCIDENT_ID, Columns.TIMESTAMP, Columns.MESSAGE_KEY, Columns.PARAMS, Columns.SUBJECT_ADDRESS) .withTtlSec(TimeUnit.HOURS.toSeconds(config.getDetailedAlarmTtlHours())) .prepare(session), CassandraQueryBuilder .select(TABLE_NAME) .addColumns(Columns.INCIDENT_ID, Columns.TIMESTAMP, Columns.MESSAGE_KEY, Columns.PARAMS, Columns.SUBJECT_ADDRESS) .addWhereColumnEquals(Columns.INCIDENT_ID) .withConsistencyLevel(ConsistencyLevel.LOCAL_ONE) .prepare(session), CassandraQueryBuilder .select(TABLE_NAME) .addColumns(Columns.INCIDENT_ID, Columns.TIMESTAMP, Columns.MESSAGE_KEY, Columns.PARAMS, Columns.SUBJECT_ADDRESS) .where(Columns.INCIDENT_ID + " = ? AND " + Columns.TIMESTAMP + " <= ?") .withConsistencyLevel(ConsistencyLevel.LOCAL_ONE) .prepare(session) ); }
Example #4
Source File: HistoryTable.java From arcusplatform with Apache License 2.0 | 6 votes |
@Inject public DetailedHubTable(@Named(CassandraHistory.NAME) Session session, HistoryAppenderConfig config) { super( CassandraQueryBuilder .insert(TABLE_NAME) .addColumns(Columns.HUB_ID, Columns.TIMESTAMP, Columns.MESSAGE_KEY, Columns.PARAMS, Columns.SUBJECT_ADDRESS) .withTtlSec(TimeUnit.HOURS.toSeconds(config.getDetailedHubTtlHours())) .prepare(session), CassandraQueryBuilder .select(TABLE_NAME) .addColumns(Columns.HUB_ID, Columns.TIMESTAMP, Columns.MESSAGE_KEY, Columns.PARAMS, Columns.SUBJECT_ADDRESS) .addWhereColumnEquals(Columns.HUB_ID) .withConsistencyLevel(ConsistencyLevel.LOCAL_ONE) .prepare(session), CassandraQueryBuilder .select(TABLE_NAME) .addColumns(Columns.HUB_ID, Columns.TIMESTAMP, Columns.MESSAGE_KEY, Columns.PARAMS, Columns.SUBJECT_ADDRESS) .where(Columns.HUB_ID + " = ? AND " + Columns.TIMESTAMP + " <= ?") .withConsistencyLevel(ConsistencyLevel.LOCAL_ONE) .prepare(session) ); }
Example #5
Source File: DeleteStatementHandlerTest.java From scalardb with Apache License 2.0 | 6 votes |
@Test public void setConsistency_DeleteOperationWithIfGiven_ShouldPrepareWithQuorumAndSerial() { // Arrange configureBehavior(null); del = prepareDeleteWithClusteringKey(); del.withCondition( new DeleteIf( new ConditionalExpression(ANY_NAME_3, new IntValue(ANY_INT_1), Operator.EQ), new ConditionalExpression(ANY_NAME_4, new TextValue(ANY_TEXT_3), Operator.EQ))) .withConsistency(Consistency.EVENTUAL); // Act handler.setConsistency(bound, del); // Assert verify(bound).setConsistencyLevel(ConsistencyLevel.QUORUM); verify(bound).setSerialConsistencyLevel(ConsistencyLevel.SERIAL); }
Example #6
Source File: HistoryTable.java From arcusplatform with Apache License 2.0 | 6 votes |
@Inject public DetailedPlaceTable(@Named(CassandraHistory.NAME) Session session, HistoryAppenderConfig config) { super( CassandraQueryBuilder .insert(TABLE_NAME) .addColumns(Columns.PLACE_ID, Columns.TIMESTAMP, Columns.MESSAGE_KEY, Columns.PARAMS, Columns.SUBJECT_ADDRESS) .withTtlSec(TimeUnit.HOURS.toSeconds(config.getDetailedPlaceTtlHours())) .prepare(session), CassandraQueryBuilder .select(TABLE_NAME) .addColumns(Columns.PLACE_ID, Columns.TIMESTAMP, Columns.MESSAGE_KEY, Columns.PARAMS, Columns.SUBJECT_ADDRESS) .addWhereColumnEquals(Columns.PLACE_ID) .withConsistencyLevel(ConsistencyLevel.LOCAL_ONE) .prepare(session), CassandraQueryBuilder .select(TABLE_NAME) .addColumns(Columns.PLACE_ID, Columns.TIMESTAMP, Columns.MESSAGE_KEY, Columns.PARAMS, Columns.SUBJECT_ADDRESS) .where(Columns.PLACE_ID + " = ? AND " + Columns.TIMESTAMP + " <= ?") .withConsistencyLevel(ConsistencyLevel.LOCAL_ONE) .prepare(session) ); }
Example #7
Source File: HistoryTable.java From arcusplatform with Apache License 2.0 | 6 votes |
@Inject public DetailedPersonTable(@Named(CassandraHistory.NAME) Session session, HistoryAppenderConfig config) { super( CassandraQueryBuilder .insert(TABLE_NAME) .addColumns(Columns.PERSON_ID, Columns.TIMESTAMP, Columns.MESSAGE_KEY, Columns.PARAMS, Columns.SUBJECT_ADDRESS) .withTtlSec(TimeUnit.HOURS.toSeconds(config.getDetailedPersonTtlHours())) .prepare(session), CassandraQueryBuilder .select(TABLE_NAME) .addColumns(Columns.PERSON_ID, Columns.TIMESTAMP, Columns.MESSAGE_KEY, Columns.PARAMS, Columns.SUBJECT_ADDRESS) .addWhereColumnEquals(Columns.PERSON_ID) .withConsistencyLevel(ConsistencyLevel.LOCAL_ONE) .prepare(session), CassandraQueryBuilder .select(TABLE_NAME) .addColumns(Columns.PERSON_ID, Columns.TIMESTAMP, Columns.MESSAGE_KEY, Columns.PARAMS, Columns.SUBJECT_ADDRESS) .where(Columns.PERSON_ID + " = ? AND " + Columns.TIMESTAMP + " <= ?") .withConsistencyLevel(ConsistencyLevel.LOCAL_ONE) .prepare(session) ); }
Example #8
Source File: HistoryTable.java From arcusplatform with Apache License 2.0 | 6 votes |
@Inject public DetailedRuleTable(@Named(CassandraHistory.NAME) Session session, HistoryAppenderConfig config) { super( CassandraQueryBuilder .insert(TABLE_NAME) .addColumns(Columns.PLACE_ID, Columns.RULE_ID, Columns.TIMESTAMP, Columns.MESSAGE_KEY, Columns.PARAMS, Columns.SUBJECT_ADDRESS) .withTtlSec(TimeUnit.HOURS.toSeconds(config.getDetailedRuleTtlHours())) .prepare(session), CassandraQueryBuilder .select(TABLE_NAME) .addColumns(Columns.PLACE_ID, Columns.RULE_ID, Columns.TIMESTAMP, Columns.MESSAGE_KEY, Columns.PARAMS, Columns.SUBJECT_ADDRESS) .addWhereColumnEquals(Columns.PLACE_ID) .addWhereColumnEquals(Columns.RULE_ID) .withConsistencyLevel(ConsistencyLevel.LOCAL_ONE) .prepare(session), CassandraQueryBuilder .select(TABLE_NAME) .addColumns(Columns.PLACE_ID, Columns.RULE_ID, Columns.TIMESTAMP, Columns.MESSAGE_KEY, Columns.PARAMS, Columns.SUBJECT_ADDRESS) .where(Columns.PLACE_ID + "= ? AND " + Columns.RULE_ID + " = ? AND " + Columns.TIMESTAMP + " <= ?") .withConsistencyLevel(ConsistencyLevel.LOCAL_ONE) .prepare(session) ); }
Example #9
Source File: CassandraProfile.java From heroic with Apache License 2.0 | 6 votes |
@Override public List<ParameterSpecification> options() { // @formatter:off return ImmutableList.of( parameter("configure", "If set, will cause the cluster to be automatically " + "configured"), parameter("type", "Type of backend to use, valid values are: " + parameters .join(types.keySet()), "<type>"), parameter("seeds", "Seeds to use when configuring backend", "<host>[:<port>][,..]"), parameter("fetchSize", "The number of results to fetch per batch", "<int>"), parameter("consistencyLevel", "The default consistency level to use", parameters.join(Arrays.stream(ConsistencyLevel.values()).map(cl -> cl.name()) .iterator())), parameter("retryPolicy", "The retry policy to use (useful when migrating " + "data)", "aggressive"), parameter("numRetries", "The number of retries to attempt for the current " + "retry policy", "<int>"), parameter("rotateHost", "The number of retries to attempt before rotating " + "host for the current retry policy", "<int>") ); // @formatter:on }
Example #10
Source File: UpdateIpcdStateColumns.java From arcusplatform with Apache License 2.0 | 6 votes |
public void execute(ExecutionContext context, boolean autoRollback) throws CommandExecutionException { Session session = context.getSession(); PreparedStatement update = session.prepare(UPDATE_STATES); BoundStatement select = session.prepare(SELECT).bind(); select.setConsistencyLevel(ConsistencyLevel.ALL); ResultSet rs = context.getSession().execute(select); for(Row row: rs) { String protocolAddress = row.getString("protocoladdress"); UUID placeId = row.getUUID("placeid"); BoundStatement bs = new BoundStatement(update); bs.setString("connState", "ONLINE"); bs.setString("registrationState", placeId == null ? "UNREGISTERED" : "REGISTERED"); bs.setString("protocolAddress", protocolAddress); session.execute(bs); } }
Example #11
Source File: CassandraStorage.java From cassandra-reaper with Apache License 2.0 | 6 votes |
@Override public Collection<RepairSegment> getSegmentsWithState(UUID runId, State segmentState) { Collection<RepairSegment> segments = Lists.newArrayList(); Statement statement = null != getRepairSegmentsByRunIdAndStatePrepStmt ? getRepairSegmentsByRunIdAndStatePrepStmt.bind(runId, segmentState.ordinal()) // legacy mode for Cassandra-2 backends : getRepairSegmentsByRunIdPrepStmt.bind(runId); if (State.STARTED == segmentState) { statement = statement.setConsistencyLevel(ConsistencyLevel.LOCAL_QUORUM); } for (Row segmentRow : session.execute(statement)) { if (segmentRow.getInt("segment_state") == segmentState.ordinal()) { segments.add(createRepairSegmentFromRow(segmentRow)); } } return segments; }
Example #12
Source File: CassandraStorage.java From copper-engine with Apache License 2.0 | 6 votes |
public CassandraStorage(final CassandraSessionManager sessionManager, final Executor executor, final RuntimeStatisticsCollector runtimeStatisticsCollector, final ConsistencyLevel consistencyLevel) { if (sessionManager == null) throw new NullArgumentException("sessionManager"); if (consistencyLevel == null) throw new NullArgumentException("consistencyLevel"); if (executor == null) throw new NullArgumentException("executor"); if (runtimeStatisticsCollector == null) throw new NullArgumentException("runtimeStatisticsCollector"); this.executor = executor; this.consistencyLevel = consistencyLevel; this.session = sessionManager.getSession(); this.cluster = sessionManager.getCluster(); this.runtimeStatisticsCollector = runtimeStatisticsCollector; }
Example #13
Source File: HistoryTable.java From arcusplatform with Apache License 2.0 | 6 votes |
@Inject public DetailedDeviceTable(@Named(CassandraHistory.NAME) Session session, HistoryAppenderConfig config) { super( CassandraQueryBuilder .insert(TABLE_NAME) .addColumns(Columns.DEVICE_ID, Columns.TIMESTAMP, Columns.MESSAGE_KEY, Columns.PARAMS, Columns.SUBJECT_ADDRESS) .withTtlSec(TimeUnit.HOURS.toSeconds(config.getDetailedDeviceTtlHours())) .prepare(session), CassandraQueryBuilder .select(TABLE_NAME) .addColumns(Columns.DEVICE_ID, Columns.TIMESTAMP, Columns.MESSAGE_KEY, Columns.PARAMS, Columns.SUBJECT_ADDRESS) .addWhereColumnEquals(Columns.DEVICE_ID) .withConsistencyLevel(ConsistencyLevel.LOCAL_ONE) .prepare(session), CassandraQueryBuilder .select(TABLE_NAME) .addColumns(Columns.DEVICE_ID, Columns.TIMESTAMP, Columns.MESSAGE_KEY, Columns.PARAMS, Columns.SUBJECT_ADDRESS) .where(Columns.DEVICE_ID + " = ? AND " + Columns.TIMESTAMP + " <= ?") .withConsistencyLevel(ConsistencyLevel.LOCAL_ONE) .prepare(session) ); }
Example #14
Source File: CassandraSearcher.java From newts with Apache License 2.0 | 6 votes |
/** * Returns the set of resource ids that match the given * term query. */ private Set<String> searchForIds(Context context, TermQuery query, ConsistencyLevel readConsistency) { Set<String> ids = Sets.newTreeSet(); BoundStatement bindStatement = m_searchStatement.bind(); bindStatement.setString(Schema.C_TERMS_CONTEXT, context.getId()); bindStatement.setString(Schema.C_TERMS_FIELD, query.getTerm().getField(Constants.DEFAULT_TERM_FIELD)); bindStatement.setString(Schema.C_TERMS_VALUE, query.getTerm().getValue()); bindStatement.setConsistencyLevel(readConsistency); for (Row row : m_session.execute(bindStatement)) { ids.add(row.getString(Constants.Schema.C_TERMS_RESOURCE)); } return ids; }
Example #15
Source File: ManagedSetupConnection.java From heroic with Apache License 2.0 | 6 votes |
@java.beans.ConstructorProperties({ "async", "seeds", "schema", "configure", "fetchSize", "readTimeout", "consistencyLevel", "retryPolicy", "authentication", "poolingOptions" }) public ManagedSetupConnection(final AsyncFramework async, final Collection<InetSocketAddress> seeds, final Schema schema, final boolean configure, final int fetchSize, final Duration readTimeout, final ConsistencyLevel consistencyLevel, final RetryPolicy retryPolicy, final DatastaxAuthentication authentication, final DatastaxPoolingOptions poolingOptions) { this.async = async; this.seeds = seeds; this.schema = schema; this.configure = configure; this.fetchSize = fetchSize; this.readTimeout = readTimeout; this.consistencyLevel = consistencyLevel; this.retryPolicy = retryPolicy; this.authentication = authentication; this.poolingOptions = poolingOptions; }
Example #16
Source File: StatementHandler.java From scalardb with Apache License 2.0 | 6 votes |
/** * Returns a {@link ConsistencyLevel} based on the specified {@link Operation} and {@link * Consistency} * * @param operation an {@code Operation} * @param consistency a {@code Consistency} * @return a {@code ConsistencyLevel} */ public static ConsistencyLevel convert(Operation operation, Consistency consistency) { switch (consistency) { case SEQUENTIAL: return ConsistencyLevel.QUORUM; case EVENTUAL: return ConsistencyLevel.ONE; case LINEARIZABLE: if (operation instanceof Selection) { // setConsistencyLevel() with SERIAL is only valid when an operation is read. // when an operation is write, it comes with conditional update and consistency level is // automatically set in overwriteConsistency(). return ConsistencyLevel.SERIAL; } else { return ConsistencyLevel.QUORUM; } default: LOGGER.warn("Unsupported consistency is specified. SEQUENTIAL is being used instead."); return ConsistencyLevel.QUORUM; } }
Example #17
Source File: DeleteStatementHandlerTest.java From scalardb with Apache License 2.0 | 5 votes |
@Test public void setConsistency_DeleteOperationWithStrongConsistencyGiven_ShouldBoundWithQuorum() { // Arrange configureBehavior(null); del = prepareDeleteWithClusteringKey(); del.withConsistency(Consistency.SEQUENTIAL); // Act handler.setConsistency(bound, del); // Assert verify(bound).setConsistencyLevel(ConsistencyLevel.QUORUM); }
Example #18
Source File: QueryCassandraTest.java From localization_nifi with Apache License 2.0 | 5 votes |
@Test public void testProcessorNoInputFlowFileAndExceptions() { setUpStandardProcessorConfig(); // Test no input flowfile testRunner.setIncomingConnection(false); testRunner.run(1, true, true); testRunner.assertAllFlowFilesTransferred(QueryCassandra.REL_SUCCESS, 1); testRunner.clearTransferState(); // Test exceptions processor.setExceptionToThrow(new NoHostAvailableException(new HashMap<InetSocketAddress, Throwable>())); testRunner.run(1, true, true); testRunner.assertAllFlowFilesTransferred(QueryCassandra.REL_RETRY, 1); testRunner.clearTransferState(); processor.setExceptionToThrow( new ReadTimeoutException(new InetSocketAddress("localhost", 9042), ConsistencyLevel.ANY, 0, 1, false)); testRunner.run(1, true, true); testRunner.assertAllFlowFilesTransferred(QueryCassandra.REL_RETRY, 1); testRunner.clearTransferState(); processor.setExceptionToThrow( new InvalidQueryException(new InetSocketAddress("localhost", 9042), "invalid query")); testRunner.run(1, true, true); // No files transferred to failure if there was no incoming connection testRunner.assertAllFlowFilesTransferred(QueryCassandra.REL_FAILURE, 0); testRunner.clearTransferState(); processor.setExceptionToThrow(new ProcessException()); testRunner.run(1, true, true); // No files transferred to failure if there was no incoming connection testRunner.assertAllFlowFilesTransferred(QueryCassandra.REL_FAILURE, 0); testRunner.clearTransferState(); processor.setExceptionToThrow(null); }
Example #19
Source File: LogConsistencyAllRetryPolicy.java From james-project with Apache License 2.0 | 5 votes |
@Override public RetryDecision onReadTimeout(Statement statement, ConsistencyLevel cl, int requiredResponses, int receivedResponses, boolean dataRetrieved, int nbRetry) { if (cl == ConsistencyLevel.ALL) { log(statement); } return DefaultRetryPolicy.INSTANCE.onReadTimeout(statement, cl, requiredResponses, receivedResponses, dataRetrieved, nbRetry); }
Example #20
Source File: CassandraSessionImpl.java From ignite with Apache License 2.0 | 5 votes |
/** * Creates instance of Cassandra driver session wrapper. * * @param builder Builder for Cassandra cluster. * @param fetchSize Number of rows to immediately fetch in CQL statement execution. * @param readConsistency Consistency level for Cassandra READ operations (select). * @param writeConsistency Consistency level for Cassandra WRITE operations (insert/update/delete). * @param log Logger. */ public CassandraSessionImpl(Cluster.Builder builder, Integer fetchSize, ConsistencyLevel readConsistency, ConsistencyLevel writeConsistency, long expirationTimeout, IgniteLogger log) { this.builder = builder; this.fetchSize = fetchSize; this.readConsistency = readConsistency; this.writeConsistency = writeConsistency; this.expirationTimeout = expirationTimeout; this.log = log; }
Example #21
Source File: JdbcRegressionUnitTest.java From cassandra-jdbc-wrapper with Apache License 2.0 | 5 votes |
@Test public void testIssue71() throws Exception { Statement stmt = con.createStatement(); // Create the target Column family String createCF = "CREATE COLUMNFAMILY t71 (k int PRIMARY KEY," + "c text " + ") ;"; stmt.execute(createCF); stmt.close(); con.close(); // open it up again to see the new CF con = DriverManager.getConnection(String.format("jdbc:cassandra://%s:%d/%s?consistency=%s",HOST,PORT,KEYSPACE,CONSISTENCY_QUORUM)); // at this point defaultConsistencyLevel should be set the QUORUM in the connection stmt = con.createStatement(); ConsistencyLevel cl = statementExtras(stmt).getConsistencyLevel(); AssertJUnit.assertTrue(ConsistencyLevel.QUORUM == cl ); System.out.println(); System.out.println("Test Issue #71"); System.out.println("--------------"); System.out.println("statement.consistencyLevel = "+ cl); }
Example #22
Source File: CassandraQueryOptions.java From iotplatform with Apache License 2.0 | 5 votes |
protected ConsistencyLevel getDefaultWriteConsistencyLevel() { if (defaultWriteConsistencyLevel == null) { if (writeConsistencyLevel != null) { defaultWriteConsistencyLevel = ConsistencyLevel.valueOf(writeConsistencyLevel.toUpperCase()); } else { defaultWriteConsistencyLevel = ConsistencyLevel.ONE; } } return defaultWriteConsistencyLevel; }
Example #23
Source File: UserUpsertOperator.java From attic-apex-malhar with Apache License 2.0 | 5 votes |
@Override public ConnectionStateManager.ConnectionBuilder withConnectionBuilder() { return ConnectionStateManager.withNewBuilder() .withSeedNodes("localhost") .withClusterNameAs("Test Cluster") .withDCNameAs("datacenter1") .withTableNameAs("users") .withKeySpaceNameAs("unittests") .withdefaultConsistencyLevel(ConsistencyLevel.LOCAL_ONE); }
Example #24
Source File: SelectStatementHandlerTest.java From scalardb with Apache License 2.0 | 5 votes |
@Test public void setConsistency_GetOperationWithStrongConsistencyGiven_ShouldPrepareWithQuorum() { // Arrange configureBehavior(null); get = prepareGetWithClusteringKey(); get.withConsistency(Consistency.SEQUENTIAL); // Act handler.setConsistency(bound, get); // Assert verify(bound).setConsistencyLevel(ConsistencyLevel.QUORUM); }
Example #25
Source File: DeleteStatementHandlerTest.java From scalardb with Apache License 2.0 | 5 votes |
private void configureBehavior(String expected) { when(session.prepare(expected == null ? anyString() : expected)).thenReturn(prepared); when(prepared.bind()).thenReturn(bound); when(bound.setString(anyInt(), anyString())).thenReturn(bound); when(bound.setInt(anyInt(), anyInt())).thenReturn(bound); when(bound.setConsistencyLevel(any(ConsistencyLevel.class))).thenReturn(bound); }
Example #26
Source File: TestCassandraTable.java From ingestion with Apache License 2.0 | 5 votes |
@Test public void save() { mockTableMetadata(); final CassandraTable table = new CassandraTable(session, tableMetadata, ConsistencyLevel.QUORUM, null); final Event event = EventBuilder .withBody("my_body".getBytes(), ImmutableMap.of("id", "1", "text_col", "my_text", "other", "foo")); table.save(ImmutableList.of(event)); verify(session).execute(argThat(new ArgumentMatcher<BatchStatement>() { @Override public boolean matches(Object o) { if (!(o instanceof BatchStatement)) { return false; } final BatchStatement batch = (BatchStatement) o; final ConsistencyLevel consistencyLevel = batch.getConsistencyLevel(); final Statement statement = batch.getStatements().iterator().next(); log.debug("Batch got consistency: {}", consistencyLevel); log.debug("Batch got insert: {}", statement); return consistencyLevel == ConsistencyLevel.QUORUM && "INSERT INTO my_keyspace.my_table(text_col,id) VALUES ('my_text',1);".equals(statement.toString()); } })); verifyNoMoreInteractions(session); }
Example #27
Source File: SelectStatementHandlerTest.java From scalardb with Apache License 2.0 | 5 votes |
@Test public void setConsistency_ScanOperationWithStrongConsistencyGiven_ShouldPrepareWithQuorum() { // Arrange configureBehavior(null); scan = prepareScan(); scan.withConsistency(Consistency.SEQUENTIAL); // Act handler.setConsistency(bound, scan); // Assert verify(bound).setConsistencyLevel(ConsistencyLevel.QUORUM); }
Example #28
Source File: SelectStatementHandlerTest.java From scalardb with Apache License 2.0 | 5 votes |
@Test public void setConsistency_GetOperationWithLinearizableConsistencyGiven_ShouldPrepareWithSerial() { // Arrange configureBehavior(null); get = prepareGetWithClusteringKey(); get.withConsistency(Consistency.LINEARIZABLE); // Act handler.setConsistency(bound, get); // Assert verify(bound).setConsistencyLevel(ConsistencyLevel.SERIAL); }
Example #29
Source File: SelectStatementHandlerTest.java From scalardb with Apache License 2.0 | 5 votes |
@Test public void setConsistency_GetOperationWithEventualConsistencyGiven_ShouldPrepareWithOne() { // Arrange configureBehavior(null); get = prepareGetWithClusteringKey(); get.withConsistency(Consistency.EVENTUAL); // Act handler.setConsistency(bound, get); // Assert verify(bound).setConsistencyLevel(ConsistencyLevel.ONE); }
Example #30
Source File: DatasourceSerializationTest.java From ignite with Apache License 2.0 | 5 votes |
/** * Serialization test. */ @Test public void serializationTest() { DataSource src = new DataSource(); Credentials cred = new CassandraAdminCredentials(); String[] points = new String[]{"127.0.0.1", "10.0.0.2", "10.0.0.3"}; LoadBalancingPolicy plc = new MyLoadBalancingPolicy(); src.setCredentials(cred); src.setContactPoints(points); src.setReadConsistency("ONE"); src.setWriteConsistency("QUORUM"); src.setLoadBalancingPolicy(plc); JavaSerializer serializer = new JavaSerializer(); ByteBuffer buff = serializer.serialize(src); DataSource _src = (DataSource)serializer.deserialize(buff); Credentials _cred = (Credentials)getFieldValue(_src, "creds"); List<InetAddress> _points = (List<InetAddress>)getFieldValue(_src, "contactPoints"); ConsistencyLevel _readCons = (ConsistencyLevel)getFieldValue(_src, "readConsistency"); ConsistencyLevel _writeCons = (ConsistencyLevel)getFieldValue(_src, "writeConsistency"); LoadBalancingPolicy _plc = (LoadBalancingPolicy)getFieldValue(_src, "loadBalancingPlc"); assertTrue("Incorrectly serialized/deserialized credentials for Cassandra DataSource", cred.getPassword().equals(_cred.getPassword()) && cred.getUser().equals(_cred.getUser())); assertTrue("Incorrectly serialized/deserialized contact points for Cassandra DataSource", "/127.0.0.1".equals(_points.get(0).toString()) && "/10.0.0.2".equals(_points.get(1).toString()) && "/10.0.0.3".equals(_points.get(2).toString())); assertTrue("Incorrectly serialized/deserialized consistency levels for Cassandra DataSource", ConsistencyLevel.ONE == _readCons && ConsistencyLevel.QUORUM == _writeCons); assertTrue("Incorrectly serialized/deserialized load balancing policy for Cassandra DataSource", _plc instanceof MyLoadBalancingPolicy); }