Package org.rioproject.impl.watch

Examples of org.rioproject.impl.watch.WatchDataSourceImpl


     * Tests the <code>getID()</code> method.
     *
     * @throws Exception if the test fails
     */
    @Test public void testGetID() throws Exception {
        WatchDataSourceImpl impl = new WatchDataSourceImpl();
        impl.setID("watch");
        Assert.assertEquals("watch", impl.getID());

        impl.setID("aaa");
        Assert.assertEquals("aaa", impl.getID());

        impl.close();
    }
View Full Code Here


     * Tests the <code>setID(String)</code> method.
     *
     * @throws Exception if the test fails
     */
    @Test public void testSetID() throws Exception {
        WatchDataSourceImpl impl = new WatchDataSourceImpl();
        impl.setID("aaa");
        Assert.assertEquals("aaa", impl.getID());

        impl.setID("");
        Assert.assertEquals("", impl.getID());

        try {
            impl.setID("bbb");
            impl.setID(null);
            Assert.fail("IllegalArgumentException expected but not thrown");
        } catch (IllegalArgumentException e) {
        }
        Assert.assertEquals("bbb", impl.getID());

        impl.close();
    }
View Full Code Here

     */
    @Test public void testGetSize() throws Exception {
        final int DCS = WatchDataSourceImpl.DEFAULT_COLLECTION_SIZE;

        {   // Default initial size
            WatchDataSourceImpl impl = new WatchDataSourceImpl();
            impl.setID("watch");
            impl.setConfiguration(EmptyConfiguration.INSTANCE);

            // Non-modified
            Assert.assertEquals(DCS, impl.getMaxSize());

            // Modified
            impl.setMaxSize(DCS + 10);
            Assert.assertEquals(DCS + 10, impl.getMaxSize());

            impl.close();
        }

        {   // Non-default initial size
            DynamicConfiguration config = new DynamicConfiguration();
            config.setEntry("org.rioproject.watch", "collectionSize",
                            DCS + 15);
            WatchDataSourceImpl impl = new WatchDataSourceImpl();
            impl.setID("watch");
            impl.setConfiguration(config);
            impl.initialize();

            // Non-modified
            Assert.assertEquals(DCS + 15, impl.getMaxSize());

            // Modified
            impl.setMaxSize(DCS + 20);
            Assert.assertEquals(DCS + 20, impl.getMaxSize());

            impl.close();
        }
    }
View Full Code Here

        final int DCS = WatchDataSourceImpl.DEFAULT_COLLECTION_SIZE;
        final int MCS = WatchDataSourceImpl.MAX_COLLECTION_SIZE;
        final int[] sizes = new int[] {-100, -2, -1, 0, 1, 2, DCS,
                MCS - 1, MCS, MCS + 1, MCS + 5};
        for (int size : sizes) {
            WatchDataSourceImpl impl = new WatchDataSourceImpl();
            impl.setID("watch");
            impl.setConfiguration(EmptyConfiguration.INSTANCE);
            // TODO: Change when fixed
            if (size < -1) {
                try {
                    impl.setMaxSize(size);
                    Assert.fail("IndexOutOfBoundsException expected"
                                + " but not thrown");
                } catch (IndexOutOfBoundsException e) {
                }
            } else {
                impl.setMaxSize(size);
                Assert.assertEquals(size, impl.getMaxSize());
            }
            impl.close();
        }
    }
View Full Code Here

     *
     * @throws Exception if the test fails
     */
    @Test public void testClear() throws Exception {
        final int DCS = WatchDataSourceImpl.DEFAULT_COLLECTION_SIZE;
        WatchDataSourceImpl impl = new WatchDataSourceImpl();
        impl.setID("watch");
        impl.setConfiguration(EmptyConfiguration.INSTANCE);

        for (int j = 0; j < DCS; j++) {
            impl.addCalculable(new Calculable());
        }
        DataSourceMonitor mon = new DataSourceMonitor(impl);
        mon.waitFor(DCS);
        int expected = Math.min(DCS, DCS);
        Assert.assertEquals(expected, impl.getCalculable().length);

        impl.clear();
        Assert.assertEquals(0, impl.getCalculable().length);

        impl.close();
    }
View Full Code Here

     *
     * @throws Exception if the test fails
     */
    @Test public void testGetCurrentSize() throws Exception {
        final int DCS = WatchDataSourceImpl.DEFAULT_COLLECTION_SIZE;
        WatchDataSourceImpl impl = new WatchDataSourceImpl();
        impl.setID("watch");
        impl.setConfiguration(EmptyConfiguration.INSTANCE);

        for (int j = 0; j < DCS; j++) {
            impl.addCalculable(new Calculable());
        }
        DataSourceMonitor mon = new DataSourceMonitor(impl);
        mon.waitFor(DCS);

        int expected = Math.min(DCS, DCS);
        Assert.assertEquals(expected, impl.getCurrentSize());

        impl.close();
    }
View Full Code Here

                else
                    wdr = new LoggingWatchDataReplicator();
                DynamicConfiguration config = new DynamicConfiguration();
                config.setEntry("org.rioproject.watch", "collectionSize", collectionSize);

                WatchDataSourceImpl impl = new WatchDataSourceImpl();
                impl.setID("watch");
                impl.setConfiguration(config);
                if(wdrClass.equals(RemoteWDR.class.getName()))
                    impl.addWatchDataReplicator(((RemoteWDR)wdr).getWatchDataReplicator());
                else
                    impl.addWatchDataReplicator(wdr);
                impl.initialize();

                /*System.out.println(
                    "WDS max size=" + impl.getMaxSize() + ", " +
                    "configured to be=" + collectionSize + ", " +
                    "count is=" + count);*/

                List<Calculable> expected = new ArrayList<Calculable>();
                for (int k = 0; k < count; k++) {
                    Calculable c = new Calculable();
                    impl.addCalculable(c);
                    expected.add(c);
                }

                if (nullCalculable) {
                    try {
                        impl.addCalculable(null);
                        Assert.fail("IllegalArgumentException expected but not thrown");
                    } catch (IllegalArgumentException e) {
                    }
                } else {
                    Calculable c = new Calculable();
                    impl.addCalculable(c);
                    expected.add(c);
                }

                long waited = 0;
                if(wdrClass.equals(RemoteWDR.class.getName())) {
                    int maxIterations = 10000;
                    int iteration = 0;
                    long current = System.currentTimeMillis();
                    while(expected.size()!=wdr.calculables().size() && iteration<maxIterations) {
                        Utils.sleep(1);
                        iteration++;
                    }
                    waited = System.currentTimeMillis()-current;
                }
                // Replicator should have all the data
                System.out.println(
                    "WDS size=" + impl.getCurrentSize() + ", " +
                    "Replicator ("+wdrClass.substring(wdrClass.indexOf("$")+1,wdrClass.length())+") " +
                    "size=" + wdr.calculables().size() +", expected size=" + expected.size()+
                    (waited==0?"":", waited="+waited+" ms"));
                Assert.assertEquals(expected.size(), wdr.calculables().size());
                Utils.assertEqualContents(expected, wdr.calculables());               

                // Data source should contain the tail
                int off = Math.max(expected.size() - collectionSize, 0);
                expected = expected.subList(off, expected.size());
                Calculable[] res = impl.getCalculable();
                Utils.assertSameContents(expected, Arrays.asList(res));

                impl.close();

                if(wdrClass.equals(RemoteWDR.class.getName()))
                    wdr.close();
            }
        }
View Full Code Here

     *
     * @throws Exception if the test fails
     */
    @Test public void testGetWatchDataReplicator() throws Exception {
        WatchDataReplicator wdr1 = new LoggingWatchDataReplicator();
        WatchDataSourceImpl impl = new WatchDataSourceImpl();
        impl.setID("watch");
        impl.setConfiguration(new DynamicConfiguration());
        impl.addWatchDataReplicator(wdr1);
        Assert.assertSame(wdr1, impl.getWatchDataReplicators()[0]);

        WatchDataReplicator wdr2 = new LoggingWatchDataReplicator();
        impl.addWatchDataReplicator(wdr2);
        Assert.assertEquals(2, impl.getWatchDataReplicators().length);
        Assert.assertSame(wdr2, impl.getWatchDataReplicators()[1]);

        impl.close();
    }
View Full Code Here

     * Tests the <code>addWatchDataReplicator(WatchDataReplicator)</code> method.
     *
     * @throws Exception if the test fails
     */
    @Test public void testAddWatchDataReplicator() throws Exception {
        WatchDataSourceImpl impl = new WatchDataSourceImpl();
        impl.setID("watch");
        impl.setConfiguration(new DynamicConfiguration());

        WatchDataReplicator wdr1 = new LoggingWatchDataReplicator();
        impl.addWatchDataReplicator(wdr1);
        Assert.assertSame(wdr1, impl.getWatchDataReplicators()[0]);

        WatchDataReplicator wdr2 = new LoggingWatchDataReplicator();
        impl.addWatchDataReplicator(wdr2);
        Assert.assertSame(wdr2, impl.getWatchDataReplicators()[1]);

        impl.addWatchDataReplicator(null);
        Assert.assertNotNull(impl.getWatchDataReplicators());
        Assert.assertTrue(impl.getWatchDataReplicators().length==2);

        impl.close();
    }
View Full Code Here

TOP

Related Classes of org.rioproject.impl.watch.WatchDataSourceImpl

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.