Package net.nelz.simplesm.test.svc

Examples of net.nelz.simplesm.test.svc.TestSvc


    @Test
    public void test() {
        final Long key1 = System.currentTimeMillis();
        final Long key2 = System.currentTimeMillis() + 10000;

        final TestSvc test = (TestSvc) context.getBean("testSvc");

        final String f1 = test.getRandomString(key1);
        final String f2 = test.getRandomString(key2);
        assertEquals(f1, test.getRandomString(key1));
        assertEquals(f2, test.getRandomString(key2));
        assertEquals(f1, test.getRandomString(key1));
        assertEquals(f2, test.getRandomString(key2));
        assertEquals(f1, test.getRandomString(key1));
        assertEquals(f2, test.getRandomString(key2));

        test.updateRandomString(key1);
        test.updateRandomString(key2);

        final String s1 = test.getRandomString(key1);
        final String s2 = test.getRandomString(key2);

        assertFalse(f1.equals(s1));
        assertFalse(f2.equals(s2));

        assertEquals(s1, test.getRandomString(key1));
        assertEquals(s2, test.getRandomString(key2));
        assertEquals(s1, test.getRandomString(key1));
        assertEquals(s2, test.getRandomString(key2));
        assertEquals(s1, test.getRandomString(key1));
        assertEquals(s2, test.getRandomString(key2));

        test.updateRandomStringAgain(key1);
        test.updateRandomStringAgain(key2);

        final String t1 = test.getRandomString(key1);
        final String t2 = test.getRandomString(key2);

        assertFalse(s1.equals(t1));
        assertFalse(s2.equals(t2));

        assertEquals(t1, test.getRandomString(key1));
        assertEquals(t2, test.getRandomString(key2));       
    }
View Full Code Here


        context = new ClassPathXmlApplicationContext("/test-context.xml");
    }

    @Test
    public void test() {
        final TestSvc test = (TestSvc) context.getBean("testSvc");

        // The full list of ids
        final List<Long> allIds = new ArrayList<Long>();

        // The list of ids whose values we do not expect to change.
        final List<Long> noChangeIds = new ArrayList<Long>();

        // The first set of ids whose values we do expect to change
        final List<Long> firstChangeIds = new ArrayList<Long>();

        // The second set of ids whose values we do expect to change
        final List<Long> secondChangeIds = new ArrayList<Long>();

        // Create the overall list, and distribute the keys to the different types
        final Long base = RandomUtils.nextLong();
        for (int ix = 0; ix < 30; ix++) {
            final Long key = base + (ix * 100);
            allIds.add(key);
            if (ix % 3 == 0) { noChangeIds.add(key); }
            if (ix % 3 == 1) { firstChangeIds.add(key); }
            if (ix % 3 == 2) { secondChangeIds.add(key); }
        }

        // Pull the generated results from the svc/dao. This is expected to be NOT cached.
        final Map<Long, String> originalMap = createMap(allIds, test.getRandomStrings(allIds));

        // Make sure successive calls to the svc/dao all generate the same results.
        assertEquals(originalMap, createMap(allIds, test.getRandomStrings(allIds)));
        assertEquals(originalMap, createMap(allIds, test.getRandomStrings(allIds)));

        // Invalidate a set of IDs, so that when the DAO is called for them again,
        // they will be regenerated.
        test.updateRandomStrings(firstChangeIds);

        final Map<Long, String> secondMap = createMap(allIds, test.getRandomStrings(allIds));

        // Firstly, make sure the new data looks differently than the old data.
        assertFalse(secondMap.equals(originalMap));

        // Loop through all the values. Make sure that any value we didn't expect to change
        // didn't, and that values we expect to be the same are.
        for (Map.Entry<Long, String> entry : secondMap.entrySet()) {
            final Long key = entry.getKey();
            if (firstChangeIds.contains(key)) {
                assertFalse(entry.getValue().equals(originalMap.get(key)));
            } else {
                assertEquals(entry.getValue(), originalMap.get(key));
            }
        }

        // Make sure successive calls to the svc/dao all generate the same results.
        assertEquals(secondMap, createMap(allIds, test.getRandomStrings(allIds)));
        assertEquals(secondMap, createMap(allIds, test.getRandomStrings(allIds)));

        // Invalidate yet another subset of the ids.
        test.updateRandomStringsAgain(secondChangeIds);

        final Map<Long, String> thirdMap = createMap(allIds, test.getRandomStrings(allIds));

        // Make sure this set of results is different from the last two sets
        assertFalse(thirdMap.equals(originalMap));
        assertFalse(thirdMap.equals(secondMap));

        // Again, loop through all the individual id/value pairs, making sure they
        // have updated or not according to our expectations.
        for (Map.Entry<Long, String> entry : thirdMap.entrySet()) {
            final Long key = entry.getKey();
            if (noChangeIds.contains(key)) {
                assertEquals(entry.getValue(), originalMap.get(key));
            }
            if (firstChangeIds.contains(key)) {
                assertEquals(entry.getValue(), secondMap.get(key));
            }
            if (secondChangeIds.contains(key)) {
                assertNotSame(entry.getValue(), originalMap.get(key));
            }
        }

        // Make sure succcessive calls to the svc/dao return the same (cached) results.
        assertEquals(thirdMap, createMap(allIds, test.getRandomStrings(allIds)));
        assertEquals(thirdMap, createMap(allIds, test.getRandomStrings(allIds)));               
    }
View Full Code Here

        context = new ClassPathXmlApplicationContext("/test-context.xml");
    }

    @Test
    public void test() {
        final TestSvc test = (TestSvc) context.getBean("testSvc");

        final List<String> result1 = test.getAssignStrings();
        final List<String> result2 = test.getAssignStrings();

        assertEquals(result1.size(), result2.size());
        for (int ix = 0; ix < result1.size(); ix++) {
            assertEquals(result1.get(ix), result2.get(ix));
        }

        test.invalidateAssignStrings();
        final List<String> result3 = test.getAssignStrings();

        // This was wrong before. The 3rd array is supposed to come
        // back different than the ones pulled before the invalidate
        assertFalse(result1.size() == result3.size());
        for (int ix = 0; ix < result1.size(); ix++) {
View Full Code Here

        context = new ClassPathXmlApplicationContext("/test-context.xml");
    }

    @Test
    public void test() {
        final TestSvc test = (TestSvc) context.getBean("testSvc");

        final List<String> result1 = test.getAssignStrings();
        final List<String> result2 = test.getAssignStrings();

        assertEquals(result1.size(), result2.size());
        for (int ix = 0; ix < result1.size(); ix++) {
            assertEquals(result1.get(ix), result2.get(ix));
        }       
View Full Code Here

        context = new ClassPathXmlApplicationContext("/test-context.xml");
    }

    @Test
    public void test() {
        final TestSvc test = (TestSvc) context.getBean("testSvc");

        final List<String> result1 = test.getAssignStrings();

        final List<String> altData = new ArrayList<String>();
        for (int ix = 0; ix < result1.size(); ix++) {
            if (ix % 2 == 0) {
                altData.add(result1.get(ix));
            }
        }

        test.updateAssignStrings(altData);
        final List<String> result2 = test.getAssignStrings();

        assertNotSame(result1.size(), result2.size());
        assertEquals(altData.size(), result2.size());
        for (int ix = 0; ix < result2.size(); ix++) {
            assertEquals(altData.get(ix), result2.get(ix));
View Full Code Here

TOP

Related Classes of net.nelz.simplesm.test.svc.TestSvc

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.