com.datastax.driver.core.WriteType Java Examples

The following examples show how to use com.datastax.driver.core.WriteType. 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: InsertStatementHandlerTest.java    From scalardb with Apache License 2.0 6 votes vote down vote up
@Test
public void handle_WTEWithCasThrown_ShouldThrowProperExecutionException()
    throws ExecutionException {
  // Arrange
  put = preparePutWithClusteringKey();
  put.withCondition(new PutIfNotExists());
  spy = prepareSpiedInsertStatementHandler();

  WriteTimeoutException toThrow = mock(WriteTimeoutException.class);
  when(toThrow.getWriteType()).thenReturn(WriteType.CAS);
  doThrow(toThrow).when(spy).handleInternal(put);

  // Act Assert
  assertThatThrownBy(
          () -> {
            spy.handle(put);
          })
      .isInstanceOf(RetriableExecutionException.class)
      .hasCause(toThrow);
}
 
Example #2
Source File: InsertStatementHandlerTest.java    From scalardb with Apache License 2.0 6 votes vote down vote up
@Test
public void
    handle_PutWithConditionGivenAndWTEWithSimpleThrown_ShouldThrowProperExecutionException()
        throws ExecutionException {
  // Arrange
  put = preparePutWithClusteringKey();
  put.withCondition(new PutIfNotExists());
  spy = prepareSpiedInsertStatementHandler();

  WriteTimeoutException toThrow = mock(WriteTimeoutException.class);
  when(toThrow.getWriteType()).thenReturn(WriteType.SIMPLE);
  doThrow(toThrow).when(spy).handleInternal(put);

  // Act Assert
  assertThatThrownBy(
          () -> {
            spy.handle(put);
          })
      .isInstanceOf(ReadRepairableExecutionException.class)
      .hasCause(toThrow);
}
 
Example #3
Source File: InsertStatementHandlerTest.java    From scalardb with Apache License 2.0 6 votes vote down vote up
@Test
public void
    handle_PutWithoutConditionGivenAndWTEWithSimpleThrown_ShouldThrowProperExecutionException()
        throws ExecutionException {
  // Arrange
  put = preparePutWithClusteringKey();
  spy = prepareSpiedInsertStatementHandler();

  WriteTimeoutException toThrow = mock(WriteTimeoutException.class);
  when(toThrow.getWriteType()).thenReturn(WriteType.SIMPLE);
  doThrow(toThrow).when(spy).handleInternal(put);

  // Act Assert
  assertThatThrownBy(
          () -> {
            spy.handle(put);
          })
      .isInstanceOf(RetriableExecutionException.class)
      .hasCause(toThrow);
}
 
Example #4
Source File: BatchHandlerTest.java    From scalardb with Apache License 2.0 6 votes vote down vote up
@Test
public void handle_WTEThrownInLoggingInBatchExecution_ShouldThrowRetriableExecutionException() {
  // Arrange
  configureBehavior();
  mutations = prepareConditionalPuts();
  WriteTimeoutException e = mock(WriteTimeoutException.class);
  when(e.getWriteType()).thenReturn(WriteType.BATCH_LOG);
  when(session.execute(any(Statement.class))).thenThrow(e);

  // Act Assert
  assertThatThrownBy(
          () -> {
            batch.handle(mutations);
          })
      .isInstanceOf(RetriableExecutionException.class)
      .hasCause(e);
}
 
Example #5
Source File: BatchHandlerTest.java    From scalardb with Apache License 2.0 6 votes vote down vote up
@Test
public void handle_WTEThrownInMutationInBatchExecution_ShouldExecuteProperly() {
  // Arrange
  configureBehavior();
  mutations = prepareConditionalPuts();
  WriteTimeoutException e = mock(WriteTimeoutException.class);
  when(e.getWriteType()).thenReturn(WriteType.BATCH);
  when(session.execute(any(Statement.class))).thenThrow(e);

  // Act Assert
  assertThatCode(
          () -> {
            batch.handle(mutations);
          })
      .doesNotThrowAnyException();
}
 
Example #6
Source File: BatchHandlerTest.java    From scalardb with Apache License 2.0 6 votes vote down vote up
@Test
public void handle_WTEThrownInCasInBatchExecution_ShouldThrowRetriableExecutionException() {
  // Arrange
  configureBehavior();
  mutations = prepareConditionalPuts();
  WriteTimeoutException e = mock(WriteTimeoutException.class);
  when(e.getWriteType()).thenReturn(WriteType.CAS);
  when(session.execute(any(Statement.class))).thenThrow(e);

  // Act Assert
  assertThatThrownBy(
          () -> {
            batch.handle(mutations);
          })
      .isInstanceOf(RetriableExecutionException.class)
      .hasCause(e);
}
 
Example #7
Source File: BatchHandlerTest.java    From scalardb with Apache License 2.0 6 votes vote down vote up
@Test
public void
    handle_WTEThrownInSimpleWriteInBatchExecution_ShouldThrowRetriableExecutionException() {
  // Arrange
  configureBehavior();
  mutations = prepareConditionalPuts();
  WriteTimeoutException e = mock(WriteTimeoutException.class);
  when(e.getWriteType()).thenReturn(WriteType.SIMPLE);
  when(session.execute(any(Statement.class))).thenThrow(e);

  // Act Assert
  assertThatThrownBy(
          () -> {
            batch.handle(mutations);
          })
      .isInstanceOf(RetriableExecutionException.class)
      .hasCause(e);
}
 
Example #8
Source File: RetryNTimesTest.java    From blueflood with Apache License 2.0 5 votes vote down vote up
@Test
public void maxTimeRetryOnWriteTimeout_shouldRethrow() throws Exception {
    RetryNTimes retryPolicy = new RetryNTimes(3, 3, 3);
    Statement mockStatement = mock( Statement.class );

    RetryPolicy.RetryDecision retryResult = retryPolicy.onWriteTimeout(mockStatement, ConsistencyLevel.LOCAL_ONE, WriteType.BATCH, 1, 0, 3);
    RetryPolicy.RetryDecision retryExpected = RetryPolicy.RetryDecision.rethrow();
    assertRetryDecisionEquals(retryExpected, retryResult);
}
 
Example #9
Source File: RetryNTimesTest.java    From blueflood with Apache License 2.0 5 votes vote down vote up
@Test
public void firstTimeRetryOnWriteTimeout_shouldRetry() throws Exception {
    RetryNTimes retryPolicy = new RetryNTimes(3, 3, 3);
    Statement mockStatement = mock( Statement.class );
    RetryPolicy.RetryDecision retryResult = retryPolicy.onWriteTimeout(mockStatement, ConsistencyLevel.LOCAL_ONE, WriteType.BATCH, 1, 0, 0);
    RetryPolicy.RetryDecision retryExpected = RetryPolicy.RetryDecision.retry(ConsistencyLevel.LOCAL_ONE);
    assertRetryDecisionEquals(retryExpected, retryResult);
}
 
Example #10
Source File: RetryNTimes.java    From blueflood with Apache License 2.0 5 votes vote down vote up
@Override
public RetryDecision onWriteTimeout(Statement stmnt, ConsistencyLevel cl,
                                    WriteType wt, int requiredResponses,
                                    int receivedResponses, int wTime) {
    if (wTime < writeAttempts) {
        LOG.info(String.format("Retrying on WriteTimeout: stmnt %s, " +
                               "consistency %s, writeType %s, requiredResponse %d, " +
                               "receivedResponse %d, rTime %d",
                stmnt, cl, wt.toString(), requiredResponses, receivedResponses, wTime));
        return RetryDecision.retry(cl);
    }
    return RetryDecision.rethrow();
}
 
Example #11
Source File: RetryPolicyWithMetrics.java    From ob1k with Apache License 2.0 5 votes vote down vote up
@Override
public RetryDecision onWriteTimeout(final Statement statement, final ConsistencyLevel cl, final WriteType writeType,
                                    final int requiredAcks, final int receivedAcks, final int nbRetry) {

  final RetryDecision decision = delegate.onWriteTimeout(statement, cl, writeType, requiredAcks, receivedAcks, nbRetry);
  for (final TagMetrics c : tagMetrics) {
    c.writeTimeouts.inc();
  }
  return decision;
}
 
Example #12
Source File: MonascaRetryPolicy.java    From monasca-persister with Apache License 2.0 5 votes vote down vote up
@Override
public RetryDecision onWriteTimeout(Statement stmnt, ConsistencyLevel cl, WriteType wt,
    int requiredResponses, int receivedResponses, int wTime) {
  if (wTime >= writeAttempts)
    return RetryDecision.rethrow();

  return RetryDecision.retry(cl);
}
 
Example #13
Source File: LogConsistencyAllRetryPolicy.java    From james-project with Apache License 2.0 5 votes vote down vote up
@Override
public RetryDecision onWriteTimeout(Statement statement, ConsistencyLevel cl, WriteType writeType, int requiredAcks, int receivedAcks, int nbRetry) {
    if (cl == ConsistencyLevel.ALL) {
        log(statement);
    }
    return DefaultRetryPolicy.INSTANCE.onWriteTimeout(statement, cl, writeType, requiredAcks, receivedAcks, nbRetry);
}
 
Example #14
Source File: AggressiveRetryPolicy.java    From heroic with Apache License 2.0 5 votes vote down vote up
@Override
public RetryDecision onWriteTimeout(
    Statement statement, ConsistencyLevel cl, WriteType writeType, int requiredAcks,
    int receivedAcks, int nbRetry
) {
    if (nbRetry != 0) {
        return RetryDecision.rethrow();
    }

    // If the batch log write failed, retry the operation as this might just be we were
    // unlucky at picking candidates
    return writeType == WriteType.BATCH_LOG ? RetryDecision.retry(cl) : RetryDecision.rethrow();
}
 
Example #15
Source File: CassandraStorage.java    From cassandra-reaper with Apache License 2.0 5 votes vote down vote up
@Override
public RetryDecision onWriteTimeout(
    Statement stmt,
    ConsistencyLevel cl,
    WriteType type,
    int required,
    int received,
    int retry) {

  Preconditions.checkState(WriteType.CAS != type ||  ConsistencyLevel.SERIAL == cl);

  return null != stmt && !Objects.equals(Boolean.FALSE, stmt.isIdempotent())
      ? WriteType.CAS == type ? RetryDecision.retry(ConsistencyLevel.ONE) : RetryDecision.retry(cl)
      : DefaultRetryPolicy.INSTANCE.onWriteTimeout(stmt, cl, type, required, received, retry);
}
 
Example #16
Source File: DriverTypeAdaptersTest.java    From simulacron with Apache License 2.0 5 votes vote down vote up
@Test
public void testShouldExtractWriteTypes() {
  assertThat(extract(SIMPLE)).isSameAs(WriteType.SIMPLE);
  assertThat(extract(BATCH)).isSameAs(WriteType.BATCH);
  assertThat(extract(UNLOGGED_BATCH)).isSameAs(WriteType.UNLOGGED_BATCH);
  assertThat(extract(COUNTER)).isSameAs(WriteType.COUNTER);
  assertThat(extract(BATCH_LOG)).isSameAs(WriteType.BATCH_LOG);
  assertThat(extract(CAS)).isSameAs(WriteType.CAS);
}
 
Example #17
Source File: DriverTypeAdaptersTest.java    From simulacron with Apache License 2.0 5 votes vote down vote up
@Test
public void testShouldAdaptWriteTypes() {
  assertThat(adapt(WriteType.SIMPLE)).isSameAs(SIMPLE);
  assertThat(adapt(WriteType.BATCH)).isSameAs(BATCH);
  assertThat(adapt(WriteType.UNLOGGED_BATCH)).isSameAs(UNLOGGED_BATCH);
  assertThat(adapt(WriteType.COUNTER)).isSameAs(COUNTER);
  assertThat(adapt(WriteType.BATCH_LOG)).isSameAs(BATCH_LOG);
  assertThat(adapt(WriteType.CAS)).isSameAs(CAS);
}
 
Example #18
Source File: BackoffRetryPolicy.java    From presto with Apache License 2.0 4 votes vote down vote up
@Override
public RetryDecision onWriteTimeout(Statement statement, ConsistencyLevel cl, WriteType writeType, int requiredAcks, int receivedAcks, int nbRetry)
{
    return DefaultRetryPolicy.INSTANCE.onWriteTimeout(statement, cl, writeType, requiredAcks, receivedAcks, nbRetry);
}
 
Example #19
Source File: AlwaysRetryPolicy.java    From copper-engine with Apache License 2.0 4 votes vote down vote up
@Override
public RetryDecision onWriteTimeout(Statement statement, ConsistencyLevel cl, WriteType writeType, int requiredAcks, int receivedAcks, int nbRetry) {
    return RetryDecision.retry(cl);
}
 
Example #20
Source File: DriverTypeAdaptersTest.java    From simulacron with Apache License 2.0 4 votes vote down vote up
@Test
public void testShouldAdaptExtractWriteTypes() {
  for (WriteType w : WriteType.values()) {
    assertThat(extract(adapt(w))).isSameAs(w);
  }
}