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

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


        ;
    }

    @Test
    public void should_find_many() throws Exception {
        CompleteBean entity1 = CompleteBeanTestBuilder.builder().randomId().name("Jonathan").buid();
        CompleteBean entity2 = CompleteBeanTestBuilder.builder().randomId().name("Paul").buid();
        CompleteBean entity3 = CompleteBeanTestBuilder.builder().randomId().name("Michael").buid();

        manager.insert(entity1);
        manager.insert(entity2);
        manager.insert(entity3);

        final CountDownLatch latch = new CountDownLatch(1);
        final AtomicReference<Object> successSpy = 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();
            }
        };

        final AchillesFuture<CompleteBean> future1 = manager.find(CompleteBean.class, entity1.getId(), withAsyncListeners(successCallBack));
        final AchillesFuture<CompleteBean> future2 = manager.find(CompleteBean.class, entity2.getId());
        final AchillesFuture<CompleteBean> future3 = manager.find(CompleteBean.class, entity3.getId());

        final CompleteBean found3 = future3.get();
        assertThat(found3).isNotNull();
        assertThat(found3.getName()).isEqualTo("Michael");

        final CompleteBean found1 = future1.get();
        assertThat(found1).isNotNull();
        assertThat(found1.getName()).isEqualTo("Jonathan");

        final CompleteBean found2 = future2.get();
        assertThat(found2).isNotNull();
        assertThat(found2.getName()).isEqualTo("Paul");

        latch.await();
        Thread.sleep(100);
        assertThat(successSpy.get()).isNotNull().isInstanceOf(CompleteBean.class)
                .isNotInstanceOf(Factory.class);
View Full Code Here


                .isNotInstanceOf(Factory.class);
    }

    @Test
    public void should_update_modifications() throws Exception {
        CompleteBean jonathan = CompleteBeanTestBuilder.builder().randomId().name("Jonathan").age(41L)
                .addFriends("bob", "alice").addPreference(1, "US").addPreference(2, "New York").buid();
        CompleteBean paul = CompleteBeanTestBuilder.builder().randomId().name("Paul").age(42L)
                .addFriends("bob", "alice").addPreference(1, "US").addPreference(2, "San Francisco").buid();
        CompleteBean george = CompleteBeanTestBuilder.builder().randomId().name("George").age(43L)
                .addFriends("bob", "alice").addPreference(1, "US").addPreference(2, "Seattle").buid();

        final CountDownLatch latch = new CountDownLatch(1);
        final AtomicReference<Object> successSpy = 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();
            }
        };
        CompleteBean managedJonathan = manager.insert(jonathan).getImmediately();
        managedJonathan.setAge(101L);
        managedJonathan.getFriends().add("eve");
        managedJonathan.getPreferences().put(1, "FR");

        CompleteBean managedPaul = manager.insert(paul).getImmediately();
        managedPaul.setAge(102L);
        managedPaul.getFriends().add("oscar");
        managedPaul.getPreferences().put(1, "CA");

        CompleteBean managedGeorge = manager.insert(george).getImmediately();
        managedGeorge.setAge(103L);
        managedGeorge.getFriends().add("mallory");
        managedGeorge.getPreferences().put(2, "Seattle");

        final AchillesFuture<CompleteBean> futureJonathan = manager.update(managedJonathan, withAsyncListeners(successCallBack));
        final AchillesFuture<CompleteBean> futurePaul = manager.update(managedPaul);
        final AchillesFuture<CompleteBean> futureGeorge = manager.update(managedGeorge);
View Full Code Here

    }


    @Test
    public void should_remove_many() throws Exception {
        CompleteBean paul = CompleteBeanTestBuilder.builder().randomId().name("Paul").buid();
        CompleteBean jack = CompleteBeanTestBuilder.builder().randomId().name("Jack").buid();
        CompleteBean john = CompleteBeanTestBuilder.builder().randomId().name("John").buid();

        paul = manager.insert(paul).getImmediately();
        jack = manager.insert(jack).getImmediately();
        john = manager.insert(john).getImmediately();

        final CountDownLatch latch = new CountDownLatch(1);
        final AtomicReference<Object> successSpy = 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();
            }
        };

        final AchillesFuture<CompleteBean> futurePaul = manager.delete(paul, withAsyncListeners(successCallBack));
        final AchillesFuture<CompleteBean> futureJack = manager.delete(jack);
        final AchillesFuture<CompleteBean> futureJohn = manager.delete(john);

        futureJohn.get();
        List<Row> rowsJohn = session.execute("select * from completebean where id=" + john.getId()).all();
        assertThat(rowsJohn).isEmpty();

        futurePaul.get();
        List<Row> rowsPaul = session.execute("select * from completebean where id=" + paul.getId()).all();
        assertThat(rowsPaul).isEmpty();
View Full Code Here

    }

    @Test
    public void should_refresh_many() throws Exception {

        CompleteBean paul = CompleteBeanTestBuilder.builder().randomId().name("Paul").addFriends("bob", "alice").age(35L).buid();
        CompleteBean john = CompleteBeanTestBuilder.builder().randomId().name("John").addFriends("bob", "alice").age(35L).buid();
        CompleteBean jack = CompleteBeanTestBuilder.builder().randomId().name("Jack").addFriends("bob", "alice").age(35L).buid();

        paul = manager.insert(paul).getImmediately();
        john = manager.insert(john).getImmediately();
        jack = manager.insert(jack).getImmediately();

        session.execute("UPDATE completebean SET name='Paul_modified' WHERE id=" + paul.getId());
        session.execute("UPDATE completebean SET friends=friends + ['eve'] WHERE id=" + paul.getId());

        session.execute("UPDATE completebean SET name='John_modified' WHERE id=" + john.getId());
        session.execute("UPDATE completebean SET friends=friends + ['oscar'] WHERE id=" + john.getId());

        session.execute("UPDATE completebean SET name='Jack_modified' WHERE id=" + jack.getId());
        session.execute("UPDATE completebean SET friends=friends + ['mallory'] WHERE id=" + jack.getId());

        final CountDownLatch latch = new CountDownLatch(1);
        final AtomicReference<Object> successSpy = 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();
            }
        };

        final AchillesFuture<CompleteBean> futurePaul = manager.refresh(paul, withAsyncListeners(successCallBack));
        final AchillesFuture<CompleteBean> futureJohn = manager.refresh(john);
        final AchillesFuture<CompleteBean> futureJack = manager.refresh(jack);

        futurePaul.get();
        assertThat(paul.getName()).isEqualTo("Paul_modified");
        assertThat(paul.getFriends()).hasSize(3);
        assertThat(paul.getFriends().get(2)).isEqualTo("eve");

        futureJohn.get();
        assertThat(john.getName()).isEqualTo("John_modified");
        assertThat(john.getFriends()).hasSize(3);
        assertThat(john.getFriends().get(2)).isEqualTo("oscar");

        futureJack.get();
        assertThat(jack.getName()).isEqualTo("Jack_modified");
        assertThat(jack.getFriends()).hasSize(3);
        assertThat(jack.getFriends().get(2)).isEqualTo("mallory");

        latch.await();
        Thread.sleep(100);
        assertThat(successSpy.get()).isNotNull().isInstanceOf(CompleteBean.class)
                .isNotExactlyInstanceOf(Factory.class);
View Full Code Here

    public void should_batch_counters() throws Exception {
        // Start batch
        Batch 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);

        final 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();
View Full Code Here

        assertThatBatchContextHasBeenReset(batch);
    }

    @Test
    public void should_batch_several_entities() 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();

        // Start batch
        Batch 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());
        Tweet foundTweet1 = manager.find(Tweet.class, tweet1.getId());
        Tweet foundTweet2 = manager.find(Tweet.class, tweet2.getId());
        User foundUser = manager.find(User.class, user.getId());

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

        // Flush
        batch.endBatch();

        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());
        foundTweet1 = manager.find(Tweet.class, tweet1.getId());
        foundTweet2 = manager.find(Tweet.class, tweet2.getId());
        foundUser = manager.find(User.class, user.getId());

        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() throws Exception {
        //Given
        CompleteBean entity = CompleteBeanTestBuilder.builder().randomId().name("name").buid();
        final Batch batch = manager.createOrderedBatch();

        //When
        batch.startBatch();

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

        batch.endBatch();

        //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() throws Exception {
        //Given
        CompleteBean entity = CompleteBeanTestBuilder.builder().randomId().name("name1000").buid();
        final Batch batch = manager.createOrderedBatch();

        //When
        batch.startBatch();

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

        batch.endBatch();

        //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

    }

    @Test
    public void should_mix_batch_with_native_statement() throws Exception {
        //Given
        CompleteBean entity1 = CompleteBeanTestBuilder.builder().randomId().name("name1000").buid();
        CompleteBean entity2 = CompleteBeanTestBuilder.builder().randomId().name("name1000").buid();

        manager.insert(entity2);

        final Batch batch = manager.createBatch();

        batch.startBatch();

        batch.insert(entity1);

        final Update.Where statement = update(CompleteBean.TABLE_NAME).with(set("name", bindMarker("name")))
                .where(eq("id", bindMarker("id")));

        //When
        batch.batchNativeStatement(statement,"DuyHai",entity2.getId());
        batch.endBatch();

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

    }

    @Test
    public void should_batch_native_statement_with_CAS_result_listener() throws Exception {
        //Given
        CompleteBean entity = CompleteBeanTestBuilder.builder().randomId().name("name1000").buid();
        manager.insert(entity);
        final Batch batch = manager.createBatch();
        final Insert statement = insertInto("CompleteBean").value("id", bindMarker("id")).value("name", bindMarker("name")).ifNotExists();

        final AtomicBoolean error = new AtomicBoolean(false);
        final AtomicReference<CASResultListener.CASResult> result = new AtomicReference<>(null);

        CASResultListener listener = new CASResultListener() {
            @Override
            public void onCASSuccess() {

            }

            @Override
            public void onCASError(CASResult casResult) {
                error.getAndSet(true);
                result.getAndSet(casResult);
            }
        };

        //When
        batch.batchNativeStatementWithCASListener(statement,listener, entity.getId(),"name");
        batch.endBatch();

        //Then
        assertThat(error.get()).isTrue();
        assertThat(result.get()).isNotNull();

        final TypedMap currentValues = result.get().currentValues();

        assertThat(currentValues.getTyped("id")).isEqualTo(entity.getId());
        assertThat(currentValues.getTyped("name")).isEqualTo("name1000");

    }
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.