@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); }
@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); }
@Test public void should_reinit_batch_context_after_exception() throws Exception { User user = UserTestBuilder.user().id(123456494L).firstname("firstname").lastname("lastname").buid(); Tweet tweet = TweetTestBuilder.tweet().randomId().content("simple_tweet").creator(user).buid(); // Start batch CQLBatchingEntityManager batchEm = emf.createBatchingEntityManager(); batchEm.startBatch(); try { batchEm.persist(tweet); } catch (AchillesException e) { batchEm.cleanBatch(); assertThatBatchContextHasBeenReset(batchEm); assertThat(batchEm.find(Tweet.class, tweet.getId())).isNull(); } // batchEm should reinit batch context batchEm.persist(user); batchEm.endBatch(); User foundUser = batchEm.find(User.class, user.getId()); assertThat(foundUser.getFirstname()).isEqualTo("firstname"); assertThat(foundUser.getLastname()).isEqualTo("lastname"); batchEm.persist(tweet); batchEm.endBatch(); Tweet foundTweet = batchEm.find(Tweet.class, tweet.getId()); assertThat(foundTweet.getContent()).isEqualTo("simple_tweet"); assertThat(foundTweet.getCreator().getId()).isEqualTo(foundUser.getId()); assertThat(foundTweet.getCreator().getFirstname()).isEqualTo("firstname"); assertThat(foundTweet.getCreator().getLastname()).isEqualTo("lastname"); assertThatBatchContextHasBeenReset(batchEm); }