Package barsuift.simLife.message

Examples of barsuift.simLife.message.PublisherTestHelper


        assertEquals(124, date.getState().getValue());
    }

    public void testPublisherAdd() {
        SimLifeDate date = new SimLifeDate();
        PublisherTestHelper publisherHelper = new PublisherTestHelper();
        publisherHelper.addSubscriberTo(date);

        date.addMillis(1);
        assertEquals(1, publisherHelper.nbUpdated());
        assertEquals(1, publisherHelper.getUpdateObjects().size());
        assertEquals(null, publisherHelper.getUpdateObjects().get(0));

        publisherHelper.reset();
        date.addMillis(1);
        assertEquals(1, publisherHelper.nbUpdated());
        assertEquals(1, publisherHelper.getUpdateObjects().size());
        assertEquals(null, publisherHelper.getUpdateObjects().get(0));

        publisherHelper.reset();
        date.addSeconds(53);
        assertEquals(1, publisherHelper.nbUpdated());
        assertEquals(1, publisherHelper.getUpdateObjects().size());
        assertEquals(null, publisherHelper.getUpdateObjects().get(0));

        publisherHelper.reset();
        date.getTimeInMillis();
        assertEquals(0, publisherHelper.nbUpdated());
        assertEquals(0, publisherHelper.getUpdateObjects().size());

        publisherHelper.reset();
        date.formatDate();
        assertEquals(0, publisherHelper.nbUpdated());
        assertEquals(0, publisherHelper.getUpdateObjects().size());
    }
View Full Code Here


        assertEquals(0, publisherHelper.getUpdateObjects().size());
    }

    public void testPublisherSet() {
        SimLifeDate date = new SimLifeDate();
        PublisherTestHelper publisherHelper = new PublisherTestHelper();
        publisherHelper.addSubscriberTo(date);

        date.setMillisOfSecond(1);
        assertEquals(1, publisherHelper.nbUpdated());
        assertEquals(1, publisherHelper.getUpdateObjects().size());
        assertEquals(null, publisherHelper.getUpdateObjects().get(0));

        publisherHelper.reset();
        date.setMillisOfSecond(1);
        assertEquals(1, publisherHelper.nbUpdated());
        assertEquals(1, publisherHelper.getUpdateObjects().size());
        assertEquals(null, publisherHelper.getUpdateObjects().get(0));

        publisherHelper.reset();
        date.setSecondOfMinute(53);
        assertEquals(1, publisherHelper.nbUpdated());
        assertEquals(1, publisherHelper.getUpdateObjects().size());
        assertEquals(null, publisherHelper.getUpdateObjects().get(0));

        publisherHelper.reset();
        date.set(999, 19, 59, Day.NOSDAY, 3, Month.TOM, 99);
        assertEquals(1, publisherHelper.nbUpdated());
        assertEquals(1, publisherHelper.getUpdateObjects().size());
        assertEquals(null, publisherHelper.getUpdateObjects().get(0));

        publisherHelper.reset();
        date.getTimeInMillis();
        assertEquals(0, publisherHelper.nbUpdated());
        assertEquals(0, publisherHelper.getUpdateObjects().size());

        publisherHelper.reset();
        date.formatDate();
        assertEquals(0, publisherHelper.nbUpdated());
        assertEquals(0, publisherHelper.getUpdateObjects().size());
    }
View Full Code Here

    protected void tearDown() throws Exception {
        super.tearDown();
    }

    public void testRun() throws Exception {
        PublisherTestHelper publisherHelper = new PublisherTestHelper();
        publisherHelper.addSubscriberTo(splitTask);

        (new Thread(splitTask)).start();
        // make sure the thread has time to start
        Thread.sleep(100);
        assertTrue(splitTask.isRunning());
        // executed once
        assertEquals(0, splitTask.getNbExecuted());
        assertEquals(0, splitTask.getNbIncrementExecuted());
        assertEquals(2, splitTask.getState().getConditionalTask().getExecutionCondition().getCount());
        assertEquals(8, splitTask.getState().getConditionalTask().getEndingCondition().getCount());
        assertEquals(0, publisherHelper.nbUpdated());
        assertEquals(0, publisherHelper.getUpdateObjects().size());

        // test we can not run the same task again
        try {
            splitTask.run();
            fail("Should throw an IllegalStateException");
        } catch (IllegalStateException ise) {
            // OK expected exception
        }

        // test we can stop it now
        splitTask.stop();
        // release the barrier
        (new Thread(barrierReleaser)).start();
        // make sure the thread has time to stop
        Thread.sleep(100);
        assertFalse(splitTask.isRunning());

        // test we can start it again
        (new Thread(splitTask)).start();
        // make sure the thread has time to start
        Thread.sleep(100);
        assertTrue(splitTask.isRunning());
        // executed once again
        assertEquals(1, splitTask.getNbExecuted());
        assertEquals(2, splitTask.getNbIncrementExecuted());
        assertEquals(1, splitTask.getState().getConditionalTask().getExecutionCondition().getCount());
        assertEquals(10, splitTask.getState().getConditionalTask().getEndingCondition().getCount());
        assertEquals(0, publisherHelper.nbUpdated());
        assertEquals(0, publisherHelper.getUpdateObjects().size());

        // release the barrier
        (new Thread(barrierReleaser)).start();
        // make sure the thread has time to execute
        Thread.sleep(100);
        assertTrue(splitTask.isRunning());
        // executed once again
        assertEquals(2, splitTask.getNbExecuted());
        assertEquals(4, splitTask.getNbIncrementExecuted());
        assertEquals(0, splitTask.getState().getConditionalTask().getExecutionCondition().getCount());
        assertEquals(12, splitTask.getState().getConditionalTask().getEndingCondition().getCount());
        assertEquals(0, publisherHelper.nbUpdated());
        assertEquals(0, publisherHelper.getUpdateObjects().size());

        splitTask.setStepSize(3);

        // release the barrier
        (new Thread(barrierReleaser)).start();
        // make sure the thread has time to execute
        Thread.sleep(100);
        assertTrue(splitTask.isRunning());
        // executed once again
        assertEquals(3, splitTask.getNbExecuted());
        assertEquals(7, splitTask.getNbIncrementExecuted());
        assertEquals(0, splitTask.getState().getConditionalTask().getExecutionCondition().getCount());
        assertEquals(15, splitTask.getState().getConditionalTask().getEndingCondition().getCount());
        assertEquals(0, publisherHelper.nbUpdated());
        assertEquals(0, publisherHelper.getUpdateObjects().size());

        // release the barrier
        (new Thread(barrierReleaser)).start();
        // make sure the thread has time to execute
        Thread.sleep(100);
        assertTrue(splitTask.isRunning());
        // executed once again
        assertEquals(4, splitTask.getNbExecuted());
        assertEquals(10, splitTask.getNbIncrementExecuted());
        assertEquals(0, splitTask.getState().getConditionalTask().getExecutionCondition().getCount());
        assertEquals(18, splitTask.getState().getConditionalTask().getEndingCondition().getCount());
        assertEquals(0, publisherHelper.nbUpdated());
        assertEquals(0, publisherHelper.getUpdateObjects().size());

        splitTask.setStepSize(20);

        // release the barrier
        (new Thread(barrierReleaser)).start();
        // make sure the thread has time to execute
        Thread.sleep(100);
        assertTrue(splitTask.isRunning());
        // executed once again
        assertEquals(5, splitTask.getNbExecuted());
        assertEquals(30, splitTask.getNbIncrementExecuted());
        assertEquals(2, splitTask.getState().getConditionalTask().getExecutionCondition().getCount());
        assertEquals(38, splitTask.getState().getConditionalTask().getEndingCondition().getCount());
        assertEquals(0, publisherHelper.nbUpdated());
        assertEquals(0, publisherHelper.getUpdateObjects().size());

        // release the barrier
        (new Thread(barrierReleaser)).start();
        // make sure the thread has time to execute
        Thread.sleep(100);
        assertTrue(splitTask.isRunning());
        // executed once again
        assertEquals(6, splitTask.getNbExecuted());
        assertEquals(50, splitTask.getNbIncrementExecuted());
        assertEquals(1, splitTask.getState().getConditionalTask().getExecutionCondition().getCount());
        assertEquals(58, splitTask.getState().getConditionalTask().getEndingCondition().getCount());
        assertEquals(0, publisherHelper.nbUpdated());
        assertEquals(0, publisherHelper.getUpdateObjects().size());

        splitTask.setStepSize(1);

        // release the barrier
        (new Thread(barrierReleaser)).start();
        // make sure the thread has time to execute
        Thread.sleep(100);
        assertTrue(splitTask.isRunning());
        // executed once again
        assertEquals(6, splitTask.getNbExecuted());
        assertEquals(50, splitTask.getNbIncrementExecuted());
        assertEquals(2, splitTask.getState().getConditionalTask().getExecutionCondition().getCount());
        assertEquals(59, splitTask.getState().getConditionalTask().getEndingCondition().getCount());
        assertEquals(0, publisherHelper.nbUpdated());
        assertEquals(0, publisherHelper.getUpdateObjects().size());

        // release the barrier
        (new Thread(barrierReleaser)).start();
        // make sure the thread has time to execute
        Thread.sleep(100);
        assertTrue(splitTask.isRunning());
        // executed once again
        assertEquals(7, splitTask.getNbExecuted());
        assertEquals(51, splitTask.getNbIncrementExecuted());
        assertEquals(0, splitTask.getState().getConditionalTask().getExecutionCondition().getCount());
        assertEquals(60, splitTask.getState().getConditionalTask().getEndingCondition().getCount());
        assertEquals(1, publisherHelper.nbUpdated());
        assertEquals(null, publisherHelper.getUpdateObjects().get(0));

        publisherHelper.reset();
        // release the barrier
        (new Thread(barrierReleaser)).start();
        // make sure the thread has time to execute
        Thread.sleep(100);
        assertFalse(splitTask.isRunning());
        // this time, the split task should have stopped
        assertEquals(7, splitTask.getNbExecuted());
        assertEquals(51, splitTask.getNbIncrementExecuted());
        assertEquals(0, splitTask.getState().getConditionalTask().getExecutionCondition().getCount());
        assertEquals(60, splitTask.getState().getConditionalTask().getEndingCondition().getCount());
        assertEquals(0, publisherHelper.nbUpdated());
        assertEquals(0, publisherHelper.getUpdateObjects().size());

        // release the barrier
        (new Thread(barrierReleaser)).start();
        // make sure the thread has time to execute
        Thread.sleep(100);
        // still stopped
        assertFalse(splitTask.isRunning());
        assertEquals(7, splitTask.getNbExecuted());
        assertEquals(51, splitTask.getNbIncrementExecuted());
        assertEquals(0, splitTask.getState().getConditionalTask().getExecutionCondition().getCount());
        assertEquals(60, splitTask.getState().getConditionalTask().getEndingCondition().getCount());
        assertEquals(0, publisherHelper.nbUpdated());
        assertEquals(0, publisherHelper.getUpdateObjects().size());
    }
View Full Code Here

     * <li>not executed</li>
     * <li>
     * </ol>
     */
    public void testRun() throws Exception {
        PublisherTestHelper publisherHelper = new PublisherTestHelper();
        publisherHelper.addSubscriberTo(conditionalRun);

        (new Thread(conditionalRun)).start();
        // make sure the thread has time to start
        Thread.sleep(100);
        assertTrue(conditionalRun.isRunning());
        // run 1
        assertEquals(0, conditionalRun.getNbExecuted());
        assertEquals(1, conditionalRun.getState().getExecutionCondition().getCount());
        assertEquals(1, conditionalRun.getState().getEndingCondition().getCount());
        assertEquals(0, publisherHelper.nbUpdated());
        assertEquals(0, publisherHelper.getUpdateObjects().size());

        // test we can not run the same task again
        try {
            conditionalRun.run();
            fail("Should throw an IllegalStateException");
        } catch (IllegalStateException ise) {
            // OK expected exception
        }

        // test we can stop it now
        conditionalRun.stop();
        // release the barrier
        (new Thread(barrierReleaser)).start();
        // make sure the thread has time to stop
        Thread.sleep(100);
        assertFalse(conditionalRun.isRunning());

        // test we can start it again
        (new Thread(conditionalRun)).start();
        // make sure the thread has time to start
        Thread.sleep(100);
        assertTrue(conditionalRun.isRunning());
        // run 2
        assertEquals(0, conditionalRun.getNbExecuted());
        assertEquals(2, conditionalRun.getState().getExecutionCondition().getCount());
        assertEquals(2, conditionalRun.getState().getEndingCondition().getCount());
        assertEquals(0, publisherHelper.nbUpdated());
        assertEquals(0, publisherHelper.getUpdateObjects().size());

        // release the barrier
        (new Thread(barrierReleaser)).start();
        // make sure the thread has time to execute
        Thread.sleep(100);
        assertTrue(conditionalRun.isRunning());
        // run 3
        assertEquals(1, conditionalRun.getNbExecuted());
        assertEquals(0, conditionalRun.getState().getExecutionCondition().getCount());
        assertEquals(3, conditionalRun.getState().getEndingCondition().getCount());
        assertEquals(0, publisherHelper.nbUpdated());
        assertEquals(0, publisherHelper.getUpdateObjects().size());


        // release the barrier
        (new Thread(barrierReleaser)).start();
        // make sure the thread has time to execute
        Thread.sleep(100);
        assertTrue(conditionalRun.isRunning());
        // run 4
        assertEquals(1, conditionalRun.getNbExecuted());
        assertEquals(1, conditionalRun.getState().getExecutionCondition().getCount());
        assertEquals(4, conditionalRun.getState().getEndingCondition().getCount());
        assertEquals(0, publisherHelper.nbUpdated());
        assertEquals(0, publisherHelper.getUpdateObjects().size());

        // release the barrier
        (new Thread(barrierReleaser)).start();
        // make sure the thread has time to execute
        Thread.sleep(100);
        assertTrue(conditionalRun.isRunning());
        // run 5
        assertEquals(1, conditionalRun.getNbExecuted());
        assertEquals(2, conditionalRun.getState().getExecutionCondition().getCount());
        assertEquals(5, conditionalRun.getState().getEndingCondition().getCount());
        assertEquals(1, publisherHelper.nbUpdated());
        assertEquals(null, publisherHelper.getUpdateObjects().get(0));

        publisherHelper.reset();
        // release the barrier
        (new Thread(barrierReleaser)).start();
        // make sure the thread has time to execute
        Thread.sleep(100);
        assertFalse(conditionalRun.isRunning());
        // run 6
        assertEquals(1, conditionalRun.getNbExecuted());
        assertEquals(2, conditionalRun.getState().getExecutionCondition().getCount());
        assertEquals(5, conditionalRun.getState().getEndingCondition().getCount());
        assertEquals(0, publisherHelper.nbUpdated());
        assertEquals(0, publisherHelper.getUpdateObjects().size());
    }
View Full Code Here

        mockEnv.setSun(mockSun);
        universe = new MockUniverse();
        universe.setEnvironment(mockEnv);

        leaf = new BasicTreeLeaf(universe, leafState);
        publisherHelper = new PublisherTestHelper();
    }
View Full Code Here

        // the task is not even in the list of tasks
        assertFalse(synchro.getTasks().contains(task));
    }

    public void testPublisher() throws Exception {
        PublisherTestHelper publisherHelper = new PublisherTestHelper();
        publisherHelper.addSubscriberTo(synchro);

        synchro.start();
        assertEquals(1, publisherHelper.nbUpdated());
        assertNull(publisherHelper.getUpdateObjects().get(0));

        publisherHelper.reset();
        Thread.sleep(Synchronizer.CYCLE_LENGTH_CORE_MS / synchro.getSpeed().getSpeed() + 100);
        synchro.stop();
        barrierReleaser.run();
        Thread.sleep(Synchronizer.CYCLE_LENGTH_CORE_MS / synchro.getSpeed().getSpeed() + 100);
        assertEquals(1, publisherHelper.nbUpdated());
        assertNull(publisherHelper.getUpdateObjects().get(0));
    }
View Full Code Here

        assertEquals(60 / synchro.getSpeed().getSpeed(), task3D.getNbExecuted());
        assertEquals(60, task3D.getNbIncrementExecuted());
    }

    public void testPublisher() throws Exception {
        PublisherTestHelper publisherHelper = new PublisherTestHelper();
        publisherHelper.addSubscriberTo(synchro);

        synchro.start();
        assertEquals(1, publisherHelper.nbUpdated());
        assertNull(publisherHelper.getUpdateObjects().get(0));

        publisherHelper.reset();
        Thread.sleep(2 * Synchronizer.CYCLE_LENGTH_CORE_MS / synchro.getSpeed().getSpeed() + 50);
        synchro.stop();
        Thread.sleep(2 * Synchronizer.CYCLE_LENGTH_CORE_MS / synchro.getSpeed().getSpeed() + 50);
        assertEquals(1, publisherHelper.nbUpdated());
        assertNull(publisherHelper.getUpdateObjects().get(0));

        publisherHelper.reset();
        synchro.oneStep();
        Thread.sleep(2 * Synchronizer.CYCLE_LENGTH_CORE_MS / synchro.getSpeed().getSpeed() + 50);
        assertEquals(2, publisherHelper.nbUpdated());
        assertNull(publisherHelper.getUpdateObjects().get(0));
    }
View Full Code Here

    protected void setUp() throws Exception {
        super.setUp();
        sunState = new SunState();
        sun = new BasicSun(sunState);
        publisherHelper = new PublisherTestHelper();
    }
View Full Code Here

        // the task is not even in the list of tasks
        assertFalse(synchro.getTasks().contains(task));
    }

    public void testPublisher() throws Exception {
        PublisherTestHelper publisherHelper = new PublisherTestHelper();
        publisherHelper.addSubscriberTo(synchro);

        synchro.start();
        assertEquals(1, publisherHelper.nbUpdated());
        assertNull(publisherHelper.getUpdateObjects().get(0));

        publisherHelper.reset();
        Thread.sleep(Synchronizer.CYCLE_LENGTH_3D_MS + 100);
        synchro.stop();
        barrierReleaser.run();
        Thread.sleep(Synchronizer.CYCLE_LENGTH_3D_MS + 100);
        assertEquals(1, publisherHelper.nbUpdated());
        assertNull(publisherHelper.getUpdateObjects().get(0));
    }
View Full Code Here

        // test with no mobile : nothing special should happen
        gravity.executeSplitConditionalStep(state.getStepSize());

        // add mobile instances
        PublisherTestHelper publisher1 = new PublisherTestHelper();
        MockMobile mobile1 = createMockMobileAtPosition(new Vector3d(1, 2, 3));
        publisher1.addSubscriberTo(mobile1);
        gravity.fall(mobile1);

        PublisherTestHelper publisher2 = new PublisherTestHelper();
        MockMobile mobile2 = createMockMobileAtPosition(new Vector3d(1, 0.076, 3));
        publisher2.addSubscriberTo(mobile2);
        gravity.fall(mobile2);
        PublisherTestHelper publisher3 = new PublisherTestHelper();
        MockMobile mobile3 = createMockMobileAtPosition(new Vector3d(1, 0.075, 3));
        publisher3.addSubscriberTo(mobile3);
        gravity.fall(mobile3);
        PublisherTestHelper publisher4 = new PublisherTestHelper();
        MockMobile mobile4 = createMockMobileAtPosition(new Vector3d(1, 0.074, 3));
        publisher4.addSubscriberTo(mobile4);
        gravity.fall(mobile4);

        PublisherTestHelper publisher5 = new PublisherTestHelper();
        MockMobile mobile5 = createMockMobileAtPosition(new Vector3d(1, 0.026, 3));
        publisher5.addSubscriberTo(mobile5);
        gravity.fall(mobile5);
        PublisherTestHelper publisher6 = new PublisherTestHelper();
        MockMobile mobile6 = createMockMobileAtPosition(new Vector3d(1, 0.025, 3));
        publisher6.addSubscriberTo(mobile6);
        gravity.fall(mobile6);
        PublisherTestHelper publisher7 = new PublisherTestHelper();
        MockMobile mobile7 = createMockMobileAtPosition(new Vector3d(1, 0.024, 3));
        publisher7.addSubscriberTo(mobile7);
        gravity.fall(mobile7);

        // with stepSize=3, the movement should be y-=0.075
        gravity.executeSplitConditionalStep(state.getStepSize());



        VectorTestHelper.assertVectorEquals(new Vector3d(1, 1.925, 3), getTranslation(mobile1));
        VectorTestHelper.assertVectorEquals(new Vector3d(1, 0.001, 3), getTranslation(mobile2));
        VectorTestHelper.assertVectorEquals(new Vector3d(1, 0, 3), getTranslation(mobile3));
        VectorTestHelper.assertVectorEquals(new Vector3d(1, 0, 3), getTranslation(mobile4));
        VectorTestHelper.assertVectorEquals(new Vector3d(1, 0, 3), getTranslation(mobile5));
        VectorTestHelper.assertVectorEquals(new Vector3d(1, 0, 3), getTranslation(mobile6));
        VectorTestHelper.assertVectorEquals(new Vector3d(1, 0, 3), getTranslation(mobile7));

        // every mobile except mobile1 and mobile2 should notify a FALLEN event
        assertEquals(0, publisher1.nbUpdated());
        assertEquals(0, publisher1.getUpdateObjects().size());
        assertEquals(0, publisher2.nbUpdated());
        assertEquals(0, publisher2.getUpdateObjects().size());

        assertEquals(1, publisher3.nbUpdated());
        assertEquals(MobileEvent.FALLEN, publisher3.getUpdateObjects().get(0));
        assertEquals(1, publisher4.nbUpdated());
        assertEquals(MobileEvent.FALLEN, publisher4.getUpdateObjects().get(0));
        assertEquals(1, publisher5.nbUpdated());
        assertEquals(MobileEvent.FALLEN, publisher5.getUpdateObjects().get(0));
        assertEquals(1, publisher6.nbUpdated());
        assertEquals(MobileEvent.FALLEN, publisher6.getUpdateObjects().get(0));
        assertEquals(1, publisher7.nbUpdated());
        assertEquals(MobileEvent.FALLEN, publisher7.getUpdateObjects().get(0));

        // only mobile1 and mobile2 should still be in the list of mobile
        assertTrue(gravity.getMobiles().contains(mobile1));
        assertTrue(gravity.getMobiles().contains(mobile2));
        assertFalse(gravity.getMobiles().contains(mobile3));
View Full Code Here

TOP

Related Classes of barsuift.simLife.message.PublisherTestHelper

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.