Ejemplo n.º 1
0
  @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);
  }
Ejemplo n.º 2
0
 @Before
 public void setUp() {
   user = UserTestBuilder.user().id(userId).firstname("fn").lastname("ln").buid();
 }