Package info.archinnov.achilles.test.integration.entity

Examples of info.archinnov.achilles.test.integration.entity.CompleteBean


    @Test
    public void should_insert_only_fields_that_are_not_null() throws Exception {
        //Given
        Long id = RandomUtils.nextLong(0,Long.MAX_VALUE);
        CompleteBean entity = new CompleteBean();
        entity.setId(id);
        entity.setName("John");
        entity.setAge(33L);

        //When
        manager2.insert(entity);
        entity.setName("Helen");
        entity.setAge(null);

        manager2.insert(entity);

        //Then
        final CompleteBean found = manager2.find(CompleteBean.class, id);

        assertThat(found.getName()).isEqualTo("Helen");
        assertThat(found.getAge()).isEqualTo(33L);

    }
View Full Code Here


    public void should_batch_counters_async() throws Exception {
        // Start batch
        AsyncBatch batch = manager.createBatch();
        batch.startBatch();

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

        entity = batch.insert(entity);

        entity.setLabel("label");

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

        entity.getVersion().incr(10L);
        batch.update(entity);

        RegularStatement selectLabel = select("label").from("CompleteBean").where(eq("id",entity.getId()));
        Map<String, Object> result = manager.nativeQuery(selectLabel).first();
        assertThat(result).isNull();

        RegularStatement selectCounter = select("counter_value")
                .from("achilles_counter_table")
                .where(eq("fqcn",CompleteBean.class.getCanonicalName()))
                .and(eq("primary_key",entity.getId().toString()))
                .and(eq("property_name","version"));

        result = manager.nativeQuery(selectCounter).first();

        assertThat(result).isNull();

        final CountDownLatch latch = new CountDownLatch(2);
        final AtomicReference<Object> successSpy = new AtomicReference<>();
        final AtomicReference<Throwable> exceptionSpy = new AtomicReference<>();

        FutureCallback<Object> successCallBack = new FutureCallback<Object>() {
            @Override
            public void onSuccess(Object result) {
                successSpy.getAndSet(result);
                latch.countDown();
            }

            @Override
            public void onFailure(Throwable t) {
                latch.countDown();
            }
        };

        FutureCallback<Object> errorCallBack = new FutureCallback<Object>() {
            @Override
            public void onSuccess(Object result) {
                latch.countDown();
            }

            @Override
            public void onFailure(Throwable t) {
                exceptionSpy.getAndSet(t);
                latch.countDown();
            }
        };

        // Flush
        batch.endBatch(successCallBack, errorCallBack);

        latch.await();

        Statement statement = new SimpleStatement("SELECT label from CompleteBean where id=" + entity.getId());
        Row row = manager.getNativeSession().execute(statement).one();
        assertThat(row.getString("label")).isEqualTo("label");

        result = manager.nativeQuery(selectCounter).first();
        assertThat(result.get("counter_value")).isEqualTo(10L);
View Full Code Here

        assertThat(exceptionSpy.get()).isNull();
    }

    @Test
    public void should_batch_several_entities_async() throws Exception {
        CompleteBean bean = CompleteBeanTestBuilder.builder().randomId().name("name").buid();
        Tweet tweet1 = TweetTestBuilder.tweet().randomId().content("tweet1").buid();
        Tweet tweet2 = TweetTestBuilder.tweet().randomId().content("tweet2").buid();

        final CountDownLatch latch = new CountDownLatch(2);
        final AtomicReference<Object> successSpy = new AtomicReference<>();
        final AtomicReference<Throwable> exceptionSpy = new AtomicReference<>();

        FutureCallback<Object> successCallBack = new FutureCallback<Object>() {
            @Override
            public void onSuccess(Object result) {
                successSpy.getAndSet(result);
                latch.countDown();
            }

            @Override
            public void onFailure(Throwable t) {
                latch.countDown();
            }
        };

        FutureCallback<Object> errorCallBack = new FutureCallback<Object>() {
            @Override
            public void onSuccess(Object result) {
                latch.countDown();
            }

            @Override
            public void onFailure(Throwable t) {
                exceptionSpy.getAndSet(t);
                latch.countDown();
            }
        };

        // Start batch
        AsyncBatch batch = manager.createBatch();
        batch.startBatch();

        batch.insert(bean);
        batch.insert(tweet1);
        batch.insert(tweet2);
        batch.insert(user);

        CompleteBean foundBean = manager.find(CompleteBean.class, bean.getId()).getImmediately();
        Tweet foundTweet1 = manager.find(Tweet.class, tweet1.getId()).getImmediately();
        Tweet foundTweet2 = manager.find(Tweet.class, tweet2.getId()).getImmediately();
        User foundUser = manager.find(User.class, user.getId()).getImmediately();

        assertThat(foundBean).isNull();
        assertThat(foundTweet1).isNull();
        assertThat(foundTweet2).isNull();
        assertThat(foundUser).isNull();

        // Flush
        batch.endBatch(successCallBack, errorCallBack);

        latch.await();

        final ResultSet resultSet = manager.getNativeSession().execute("SELECT id,favoriteTweets,followers,friends,age_in_years,name,welcomeTweet,label,preferences FROM CompleteBean WHERE id=:id", bean.getId());
        assertThat(resultSet.all()).hasSize(1);

        foundBean = manager.find(CompleteBean.class, bean.getId()).getImmediately();
        foundTweet1 = manager.find(Tweet.class, tweet1.getId()).getImmediately();
        foundTweet2 = manager.find(Tweet.class, tweet2.getId()).getImmediately();
        foundUser = manager.find(User.class, user.getId()).getImmediately();

        assertThat(foundBean.getName()).isEqualTo("name");
        assertThat(foundTweet1.getContent()).isEqualTo("tweet1");
        assertThat(foundTweet2.getContent()).isEqualTo("tweet2");
        assertThat(foundUser.getFirstname()).isEqualTo("fn");
        assertThat(foundUser.getLastname()).isEqualTo("ln");
        assertThatBatchContextHasBeenReset(batch);
View Full Code Here

    }

    @Test
    public void should_order_batch_operations_on_the_same_column_with_insert_and_update_async() throws Exception {
        //Given
        CompleteBean entity = CompleteBeanTestBuilder.builder().randomId().name("name").buid();
        final AsyncBatch batch = manager.createOrderedBatch();

        //When
        batch.startBatch();

        entity = batch.insert(entity);
        entity.setLabel("label");
        batch.update(entity);

        batch.endBatch().getImmediately();

        //Then
        Statement statement = new SimpleStatement("SELECT label from CompleteBean where id=" + entity.getId());
        Row row = manager.getNativeSession().execute(statement).one();
        assertThat(row.getString("label")).isEqualTo("label");
    }
View Full Code Here


    @Test
    public void should_order_batch_operations_on_the_same_column_async() throws Exception {
        //Given
        CompleteBean entity = CompleteBeanTestBuilder.builder().randomId().name("name1000").buid();
        final AsyncBatch batch = manager.createOrderedBatch();

        //When
        batch.startBatch();

        entity = batch.insert(entity);
        entity.setName("name");
        batch.update(entity);

        batch.endBatch().getImmediately();

        //Then
        Statement statement = new SimpleStatement("SELECT name from CompleteBean where id=" + entity.getId());
        Row row = manager.getNativeSession().execute(statement).one();
        assertThat(row.getString("name")).isEqualTo("name");
    }
View Full Code Here

            public void onFailure(Throwable t) {
                exceptionSpy.getAndSet(t);
                latch.countDown();
            }
        };
        final CompleteBean proxy = manager.getProxy(CompleteBean.class, 10L).getImmediately();

        //When
        manager.refresh(proxy, withAsyncListeners(exceptionCallBack));

        latch.await();
View Full Code Here


    @Test
    public void should_re_prepare_statements_when_cache_size_exceeded() throws Exception {
        //Given
        CompleteBean bean = builder().id(RandomUtils.nextLong(0,Long.MAX_VALUE)).name("name").buid();

        CompleteBean managed = pm.insert(bean);

        //When
        managed.setAge(10L);
        pm.update(managed);

        managed.setFriends(Arrays.asList("foo", "bar"));
        pm.update(managed);

        managed.setFollowers(Sets.newHashSet("George", "Paul"));
        pm.update(managed);

        managed.setAge(11L);
        pm.update(managed);

        //Then
        CompleteBean found = pm.find(CompleteBean.class, bean.getId());

        assertThat(found.getAge()).isEqualTo(11L);
        assertThat(found.getName()).isEqualTo("name");
        assertThat(found.getFriends()).containsExactly("foo", "bar");
        assertThat(found.getFollowers()).containsOnly("George", "Paul");
    }
View Full Code Here

    @Test
    public void should_persist_many() throws Exception {

        final CountDownLatch latch = new CountDownLatch(1);
        CompleteBean paul = CompleteBeanTestBuilder.builder().randomId().name("Paul").version(CounterBuilder.incr(11L)).buid();
        CompleteBean george = CompleteBeanTestBuilder.builder().randomId().name("George").version(CounterBuilder.incr(12L)).buid();
        CompleteBean michael = CompleteBeanTestBuilder.builder().randomId().name("Michael").version(CounterBuilder.incr(13L)).buid();

        final AtomicReference<Object> spy = new AtomicReference<>();
        FutureCallback<Object> callback = new FutureCallback<Object>() {
            @Override
            public void onSuccess(Object result) {
                spy.getAndSet(result);
            }

            @Override
            public void onFailure(Throwable t) {

            }
        };

        final AchillesFuture<CompleteBean> futureEntity1 = manager.insert(paul, withAsyncListeners(callback));
        final AchillesFuture<CompleteBean> futureEntity2 = manager.insert(george);
        final AchillesFuture<CompleteBean> futureEntity3 = manager.insert(michael);

        Callable<CompleteBean> callable = new Callable<CompleteBean>() {
            @Override
            public CompleteBean call() throws Exception {
                futureEntity1.get();
                futureEntity2.get();
                final CompleteBean entity3 = futureEntity3.get();
                latch.countDown();
                return entity3;
            }
        };
View Full Code Here

    }

    @Test
    public void should_persist_with_success_and_error_async() throws Exception {
        //Given
        CompleteBean paul = CompleteBeanTestBuilder.builder().randomId().name("Paul").buid();
        CompleteBean george = CompleteBeanTestBuilder.builder().randomId().name("George").buid();

        manager.insert(paul);

        final CountDownLatch latch = new CountDownLatch(1);
        final AtomicReference<Object> successSpy = new AtomicReference<>();
View Full Code Here

    }

    @Test
    public void should_not_notify_async_listener_if_cas_listener_provided() throws Exception {
        //Given
        CompleteBean paul = CompleteBeanTestBuilder.builder().randomId().name("Paul").buid();

        manager.insert(paul);

        final CountDownLatch latch = new CountDownLatch(1);
        final AtomicReference<Throwable> exceptionSpy = new AtomicReference<>();
View Full Code Here

TOP

Related Classes of info.archinnov.achilles.test.integration.entity.CompleteBean

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.