예제 #1
0
  @Test
  public void should_reinit_batch_context_and_consistency_after_exception() throws Exception {
    Tweet tweet1 = TweetTestBuilder.tweet().randomId().content("simple_tweet1").buid();
    Tweet tweet2 = TweetTestBuilder.tweet().randomId().content("simple_tweet2").buid();

    em.persist(tweet1);

    // Start batch
    CQLBatchingEntityManager batchEm = emf.createBatchingEntityManager();
    batchEm.startBatch();

    batchEm.startBatch(EACH_QUORUM, EACH_QUORUM);
    batchEm.persist(tweet2);

    try {
      batchEm.endBatch();
    } catch (Exception e) {
      assertThatBatchContextHasBeenReset(batchEm);
    }

    Thread.sleep(1000);
    logAsserter.prepareLogLevel();
    batchEm.persist(tweet2);
    batchEm.endBatch();
    logAsserter.assertConsistencyLevels(ONE, ONE);
  }
예제 #2
0
  @Test
  public void should_batch_with_custom_consistency_level() throws Exception {
    Tweet tweet1 = TweetTestBuilder.tweet().randomId().content("simple_tweet1").buid();
    Tweet tweet2 = TweetTestBuilder.tweet().randomId().content("simple_tweet2").buid();
    Tweet tweet3 = TweetTestBuilder.tweet().randomId().content("simple_tweet3").buid();

    em.persist(tweet1);

    // Start batch
    CQLBatchingEntityManager batchEm = emf.createBatchingEntityManager();
    batchEm.startBatch();

    batchEm.startBatch(QUORUM, ALL);

    logAsserter.prepareLogLevel();

    Tweet foundTweet1 = batchEm.find(Tweet.class, tweet1.getId());

    assertThat(foundTweet1.getContent()).isEqualTo(tweet1.getContent());

    batchEm.persist(tweet2);
    batchEm.persist(tweet3);

    batchEm.endBatch();

    logAsserter.assertConsistencyLevels(QUORUM, ALL);
    assertThatBatchContextHasBeenReset(batchEm);
  }