Package org.rioproject.impl.watch

Examples of org.rioproject.impl.watch.WatchDataSourceImpl


        // id
        final String ids[] = new String[]{"1-2", "watch", "aBcde"};
        for (String id : ids) {
            //WatchDataSource wds = new WatchDataSourceImpl(
            //        id, null, EmptyConfiguration.INSTANCE).export();
            WatchDataSource wds = new WatchDataSourceImpl();
            wds.setConfiguration(EmptyConfiguration.INSTANCE);
            wds.initialize();
            //wds.setID(id);
            //wds.initialize();

            Watch watch = construct4(wds, id);
            Assert.assertEquals(id, watch.getId());
            testInstance(watch);
            Utils.close(watch.getWatchDataSource());
        }

        // Illegal id
        try {
            String id = null;
            WatchDataSourceImpl wdsi = new WatchDataSourceImpl();
            wdsi.setID("");
            wdsi.setConfiguration(EmptyConfiguration.INSTANCE);
            WatchDataSource wds = wdsi.export();

            construct4(wds, id);
            Assert.fail("IllegalArgumentException expected but not thrown");
        } catch (IllegalArgumentException e) {
        }
        try {
            String id = "";
            construct1(id);
            Assert.fail("IllegalArgumentException expected");
        } catch (IllegalArgumentException e) {
        }

        // watchDataSource
        final int collectionSizes[] = new int[]{1, 1000, 5000};
        for (int collectionSize : collectionSizes) {
            DynamicConfiguration config = new DynamicConfiguration();
            config.setEntry("org.rioproject.watch", "collectionSize",
                            collectionSize);
            //WatchDataSource wds = new WatchDataSourceImpl("", null,
            //                                              config).export();
            WatchDataSource wds = new WatchDataSourceImpl();
            wds.setConfiguration(config);

            Watch watch = construct4(wds, "watch");
            Assert.assertSame(wds, watch.getWatchDataSource());
            checkInstance(watch, collectionSize, false);
            Utils.close(watch.getWatchDataSource());
View Full Code Here


     *
     * @throws Exception if the test fails
     */
    @Test
    public void testGetSetWatchDataSource() throws Exception {
        WatchDataSourceImpl wdsi = new WatchDataSourceImpl();
        wdsi.setID("wds");
        wdsi.setConfiguration(EmptyConfiguration.INSTANCE);
        WatchDataSource wds = wdsi.export();
        Watch watch = construct4(wds, "watch");
        Assert.assertSame(wds, watch.getWatchDataSource());

        WatchDataSourceImpl wdsi2 = new WatchDataSourceImpl();
        wdsi2.setID("otherWds");
        wdsi2.setConfiguration(EmptyConfiguration.INSTANCE);
        WatchDataSource otherWds = wdsi2.export();
               
        watch.setWatchDataSource(otherWds);
        Assert.assertSame(otherWds, watch.getWatchDataSource());

        watch.setWatchDataSource(null);
View Full Code Here

     *
     * @throws Exception if the test fails
     */
    @Test public void testGetCalculable1() throws Exception {
        final int DCS = WatchDataSourceImpl.DEFAULT_COLLECTION_SIZE;
        WatchDataSourceImpl impl = new WatchDataSourceImpl();
        impl.setID("watch");
        impl.setConfiguration(EmptyConfiguration.INSTANCE);
        List<Calculable> expected = new ArrayList<Calculable>();
        for (int j = 0; j < DCS; j++) {
            Calculable c = new Calculable();
            impl.addCalculable(c);
            expected.add(c);
        }
        DataSourceMonitor mon = new DataSourceMonitor(impl);
        mon.waitFor(DCS);

        int off = Math.max(expected.size() - DCS, 0);
        expected = expected.subList(off, expected.size());
        Calculable[] res = impl.getCalculable();
        Utils.assertSameContents(expected, Arrays.asList(res));

        impl.close();
    }
View Full Code Here

     *
     * @throws Exception if the test fails
     */
    @Test public void testGetLastCalculable1() throws Exception {
        final int DCS = WatchDataSourceImpl.DEFAULT_COLLECTION_SIZE;
        WatchDataSourceImpl impl = new WatchDataSourceImpl();
        impl.setID("watch");
        impl.setConfiguration(EmptyConfiguration.INSTANCE);
        Calculable expected = null;
        for (int j = 0; j < DCS; j++) {
            Calculable c = new Calculable();
            impl.addCalculable(c);
            expected = c;
        }
        DataSourceMonitor mon = new DataSourceMonitor(impl);
        mon.waitFor(DCS);

        Assert.assertSame(expected, impl.getLastCalculable());

        impl.close();
    }
View Full Code Here

     * Tests the <code>getThresholdValues()<code> method.
     *
     * @throws Exception if the test fails
     */
    @Test public void testGetThresholdValues() throws Exception {
        WatchDataSourceImpl impl = new WatchDataSourceImpl();
        impl.setID("watch");
        impl.setConfiguration(EmptyConfiguration.INSTANCE);
        ThresholdValues tv = impl.getThresholdValues();
        Assert.assertNotNull(tv);

        tv = new ThresholdValues();
        impl.setThresholdValues(tv);
        Assert.assertSame(tv, impl.getThresholdValues());

        impl.close();
    }
View Full Code Here

     * Tests the <code>getShresholdValues<code> method.
     *
     * @throws Exception if the test fails
     */
    @Test public void testSetThresholdValues() throws Exception {
        WatchDataSourceImpl impl = new WatchDataSourceImpl();
        impl.setID("watch");
        impl.setConfiguration(EmptyConfiguration.INSTANCE);

        ThresholdValues tv = new ThresholdValues();
        impl.setThresholdValues(tv);
        Assert.assertSame(tv, impl.getThresholdValues());

        // TODO: Change when fixed
        impl.setThresholdValues(null);
        Assert.assertSame(tv, impl.getThresholdValues());

        impl.close();
    }
View Full Code Here

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

        impl.setView("abcd");
        Assert.assertEquals("abcd", impl.getView());

        impl.close();
    }
View Full Code Here

     * Tests the <code>setView(String)</code> method.
     *
     * @throws Exception if the test fails
     */
    @Test public void testSetView() throws Exception {
        WatchDataSourceImpl impl = new WatchDataSourceImpl();
        impl.setID("watch");
        impl.setConfiguration(EmptyConfiguration.INSTANCE);

        impl.setView("abcd");
        Assert.assertEquals("abcd", impl.getView());

        impl.setView("");
        Assert.assertEquals("", impl.getView());

        impl.setView(null);
        Assert.assertEquals(null, impl.getView());

        impl.close();
    }
View Full Code Here

                counts, counts});
        for (Object[] combination : combinations) {
            int exportCount = (Integer) combination[0];
            int unexportCount = (Integer) combination[1];

            WatchDataSourceImpl impl = new WatchDataSourceImpl();
            impl.setID("watch");
            impl.setConfiguration(EmptyConfiguration.INSTANCE);

            for (int j = 0; j < exportCount; j++) {
                impl.export();
            }
            for (int j = 0; j < unexportCount; j++) {
                impl.unexport(true);
            }

            if (exportCount == 0 || unexportCount > 0) {
                // TODO: Is this correct? IllegalStateException is better
                try {
                    impl.getProxyVerifier();
                    Assert.fail("IllegalArgumentException expected"
                                + " but not thrown");
                } catch (IllegalArgumentException e) {
                }
            } else {
                Assert.assertNotNull(impl.getProxyVerifier());
            }

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

            if (collectionSize != 666) {
                config.setEntry("org.rioproject.watch",
                                "collectionSize",
                                collectionSize);
            }
            WatchDataSourceImpl impl = new WatchDataSourceImpl(id, config);
            boolean added = impl.addWatchDataReplicator(wdr);
            if(wdr!=null)
                Assert.assertTrue("Expected to add "+wdr.getClass().getName(),
                                  added);
            else
                Assert.assertFalse("Expected to not add a null WatchDataReplicator",
                                   added);

            Assert.assertSame(id, impl.getID());
            if (wdr == null) {
                Assert.assertNotNull(impl.getWatchDataReplicators());
                Assert.assertTrue(impl.getWatchDataReplicators().length==0);
            } else {
                Assert.assertSame(wdr, impl.getWatchDataReplicators()[0]);
            }
            if (collectionSize == 666 || collectionSize < 1
                || collectionSize > MCS) {
                Assert.assertEquals(DCS, impl.getMaxSize());
            } else {
                Assert.assertEquals(collectionSize, impl.getMaxSize());
            }

            Assert.assertNull(impl.getProxy());
            assertAddCalculableWorks(impl,
                                     Math.min(Math.max(collectionSize, 0), 10),
                                     true);

            impl.close();
        }

        try {
            new WatchDataSourceImpl(null, new DynamicConfiguration());
            Assert.fail("IllegalArgumentException expected but not thrown");
        } catch (IllegalArgumentException e) {
        }
        try {
            new WatchDataSourceImpl("watch", null);
            Assert.fail("IllegalArgumentException expected but not thrown");
        } catch (IllegalArgumentException e) {
        }
        try {
            new WatchDataSourceImpl(null, null);
            Assert.fail("IllegalArgumentException expected but not thrown");
        } catch (IllegalArgumentException e) {
        }
    }
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.