コード例 #1
0
ファイル: InitializeIT.java プロジェクト: Stefanic/Achilles
  @Test
  public void should_initialize_lazy_properties() throws Exception {
    Tweet tweet = new Tweet();
    tweet.setId(UUIDGen.getTimeUUID());
    tweet.setContent("welcome");

    CompleteBean entity =
        CompleteBeanTestBuilder.builder()
            .randomId()
            .name("name")
            .label("label")
            .age(45L)
            .addFriends("foo", "bar")
            .welcomeTweet(tweet)
            .version(CounterBuilder.incr(11L))
            .buid();

    manager.insert(entity);

    CompleteBean foundEntity = manager.find(CompleteBean.class, entity.getId());

    CompleteBean rawEntity = manager.initAndRemoveProxy(foundEntity);

    assertThat(rawEntity.getName()).isEqualTo("name");
    assertThat(rawEntity.getLabel()).isEqualTo("label");
    assertThat(rawEntity.getAge()).isEqualTo(45L);
    assertThat(rawEntity.getFriends()).containsExactly("foo", "bar");
    assertThat(rawEntity.getWelcomeTweet().getContent()).isEqualTo("welcome");
    assertThat(rawEntity.getVersion()).isInstanceOf(InternalCounterImpl.class);
    assertThat(rawEntity.getVersion().get()).isEqualTo(11L);
  }
コード例 #2
0
ファイル: InitializeIT.java プロジェクト: Stefanic/Achilles
  @Test
  public void should_initialize_counter_value() throws Exception {
    CompleteBean entity = CompleteBeanTestBuilder.builder().randomId().name("name").buid();

    entity = manager.insert(entity);

    entity.getVersion().incr(2L);

    manager.update(entity);

    RegularStatement statement = select().from("CompleteBean").where(eq("id", bindMarker()));

    CompleteBean foundEntity =
        manager.typedQuery(CompleteBean.class, statement, entity.getId()).getFirst();

    CompleteBean rawEntity = manager.initAndRemoveProxy(foundEntity);

    assertThat(rawEntity.getVersion()).isInstanceOf(InternalCounterImpl.class);
    assertThat(rawEntity.getVersion().get()).isEqualTo(2L);
  }
コード例 #3
0
ファイル: BatchModeIT.java プロジェクト: nnguyen07/Achilles
  @Test
  public void should_batch_counters() throws Exception {
    // Start batch
    CQLBatchingEntityManager batchEm = emf.createBatchingEntityManager();
    batchEm.startBatch();

    CompleteBean entity = CompleteBeanTestBuilder.builder().randomId().name("name").buid();

    entity = batchEm.merge(entity);

    entity.setLabel("label");

    Tweet welcomeTweet = TweetTestBuilder.tweet().randomId().content("welcomeTweet").buid();
    entity.setWelcomeTweet(welcomeTweet);

    entity.getVersion().incr(10L);
    batchEm.merge(entity);

    Row result = session.execute("SELECT label from CompleteBean where id=" + entity.getId()).one();
    assertThat(result).isNull();

    result =
        session
            .execute(
                "SELECT counter_value from achilles_counter_table where fqcn='"
                    + CompleteBean.class.getCanonicalName()
                    + "' and primary_key='"
                    + entity.getId()
                    + "' and property_name='version'")
            .one();
    assertThat(result.getLong("counter_value")).isEqualTo(10L);

    // Flush
    batchEm.endBatch();

    result = session.execute("SELECT label from CompleteBean where id=" + entity.getId()).one();
    assertThat(result.getString("label")).isEqualTo("label");

    result =
        session
            .execute(
                "SELECT counter_value from achilles_counter_table where fqcn='"
                    + CompleteBean.class.getCanonicalName()
                    + "' and primary_key='"
                    + entity.getId()
                    + "' and property_name='version'")
            .one();
    assertThat(result.getLong("counter_value")).isEqualTo(10L);
    assertThatBatchContextHasBeenReset(batchEm);
  }