Java Code Examples for com.datastax.driver.core.ConsistencyLevel#QUORUM
The following examples show how to use
com.datastax.driver.core.ConsistencyLevel#QUORUM .
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: 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 2
Source File: CassandraConsistenciesConfiguration.java From james-project with Apache License 2.0 | 5 votes |
public static ConsistencyLevel fromString(String value) { switch (value) { case "QUORUM": return ConsistencyLevel.QUORUM; case "LOCAL_QUORUM": return ConsistencyLevel.LOCAL_QUORUM; case "EACH_QUORUM": return ConsistencyLevel.EACH_QUORUM; case "SERIAL": return ConsistencyLevel.SERIAL; case "LOCAL_SERIAL": return ConsistencyLevel.LOCAL_SERIAL; } throw new IllegalArgumentException("'" + value + "' is not a value ConsistencyLevel"); }
Example 3
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 4
Source File: TestCassandraTable.java From ingestion with Apache License 2.0 | 5 votes |
@Test public void saveUnmappable() { mockTableMetadata(); final CassandraTable table = new CassandraTable(session, tableMetadata, ConsistencyLevel.QUORUM, null); final Event event = EventBuilder .withBody("my_body".getBytes(), ImmutableMap.of("XXXid", "1", "XXXtext_col", "my_text")); table.save(ImmutableList.of(event)); verifyZeroInteractions(session); }
Example 5
Source File: TestCassandraTable.java From ingestion with Apache License 2.0 | 5 votes |
@Test public void saveWithNoPrimaryKey() { mockTableMetadata(); final CassandraTable table = new CassandraTable(session, tableMetadata, ConsistencyLevel.QUORUM, null); final Event event = EventBuilder .withBody("my_body".getBytes(), ImmutableMap.of("XXXid", "1", "text_col", "my_text")); table.save(ImmutableList.of(event)); verifyZeroInteractions(session); }
Example 6
Source File: TestCassandraTable.java From ingestion with Apache License 2.0 | 5 votes |
@Test public void saveEmpty() { mockTableMetadata(); final CassandraTable table = new CassandraTable(session, tableMetadata, ConsistencyLevel.QUORUM, null); table.save(ImmutableList.<Event>of()); verifyZeroInteractions(session); }
Example 7
Source File: TestCassandraTable.java From ingestion with Apache License 2.0 | 5 votes |
@Test public void parseWithoutBody() { 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")); final Map<String, Object> parsedEvent = table.parse(event); assertThat(parsedEvent.size()).isEqualTo(2); assertThat(parsedEvent.get("id")).isEqualTo(1); assertThat(parsedEvent.get("text_col")).isEqualTo("my_text"); }
Example 8
Source File: TestCassandraTable.java From ingestion with Apache License 2.0 | 5 votes |
@Test public void parseWithBody() { mockTableMetadata(); final CassandraTable table = new CassandraTable(session, tableMetadata, ConsistencyLevel.QUORUM, "text_col"); final Event event = EventBuilder .withBody("my_body".getBytes(), ImmutableMap.of("id", "1", "text_col", "my_text", "other", "foo")); final Map<String, Object> parsedEvent = table.parse(event); assertThat(parsedEvent.size()).isEqualTo(2); assertThat(parsedEvent.get("id")).isEqualTo(1); assertThat(parsedEvent.get("text_col")).isEqualTo("my_body"); }
Example 9
Source File: CentralModule.java From glowroot with Apache License 2.0 | 4 votes |
@Value.Default ConsistencyLevel cassandraReadConsistencyLevel() { return ConsistencyLevel.QUORUM; }
Example 10
Source File: CentralModule.java From glowroot with Apache License 2.0 | 4 votes |
@Value.Default ConsistencyLevel cassandraWriteConsistencyLevel() { return ConsistencyLevel.QUORUM; }
Example 11
Source File: ConstructorConfiguredCqlClientFactory.java From storm-cassandra-cql with Apache License 2.0 | 4 votes |
public ConstructorConfiguredCqlClientFactory(String hosts) { this(hosts, null, ConsistencyLevel.QUORUM, QueryOptions.DEFAULT_SERIAL_CONSISTENCY_LEVEL, ProtocolOptions.Compression.NONE); }
Example 12
Source File: TestCassandraSink.java From ingestion with Apache License 2.0 | 4 votes |
@Test public void thatParseWorksOnIgnoreCase() throws EventDeliveryException { final CassandraSink sink = new CassandraSink(); final Channel channel = mock(Channel.class); final Transaction tx = mock(Transaction.class); final Session session = mock(Session.class); final ConsistencyLevel consistencyLevel = ConsistencyLevel.QUORUM; String bodyColumn = null; TableMetadata tableMetadata = mock(TableMetadata.class); // we want to test the method CassandraTable.parse so...we don't mock it final CassandraTable tableWithoutIgnoreCase = new CassandraTable(session, tableMetadata, consistencyLevel, bodyColumn); // create a context without ignore case final Context ctx = new Context(); ctx.put("tables", "keyspace.table"); sink.configure(ctx); sink.tables = Collections.singletonList(tableWithoutIgnoreCase); sink.setChannel(channel); when(channel.getTransaction()).thenReturn(tx); // mock table metadata mockTableMetadataWithIdAndNameColumns(tableMetadata); // put event names in upper case final Event event = EventBuilder.withBody(new byte[0], ImmutableMap.of("ID", "1", "NAME", "text")); // parsed result should be empty final Map<String, Object> parsedResult = tableWithoutIgnoreCase.parse(event); assertThat(parsedResult).isEmpty(); // now with ignore case --> should be some results final CassandraTable tableWitIgnoreCase = new CassandraTable(session, tableMetadata, consistencyLevel, bodyColumn, true); ctx.put("ignoreCase", "true"); final Map<String, Object> parsedResultIgnoreCase = tableWitIgnoreCase.parse(event); assertThat(parsedResultIgnoreCase).isNotEmpty(); assertThat(parsedResultIgnoreCase.get("id")).isNotNull(); }