Package com.alibaba.mtc.testmodel

Examples of com.alibaba.mtc.testmodel.FooPojo


    public void test_MtContextRunnable_copyObject() throws Exception {
        ConcurrentMap<String, MtContextThreadLocal<FooPojo>> mtContexts =
                new ConcurrentHashMap<String, MtContextThreadLocal<FooPojo>>();

        MtContextThreadLocal<FooPojo> parent = new FooMtContextThreadLocal();
        parent.set(new FooPojo(PARENT_UNMODIFIED_IN_CHILD, 1));
        mtContexts.put(PARENT_UNMODIFIED_IN_CHILD, parent);

        MtContextThreadLocal<FooPojo> p = new FooMtContextThreadLocal();
        p.set(new FooPojo(PARENT_MODIFIED_IN_CHILD, 2));
        mtContexts.put(PARENT_MODIFIED_IN_CHILD, p);

        FooTask task = new FooTask("1", mtContexts);
        MtContextRunnable mtContextRunnable = MtContextRunnable.get(task);

        // create after new Task, won't see parent value in in task!
        MtContextThreadLocal<FooPojo> after = new FooMtContextThreadLocal();
        after.set(new FooPojo(PARENT_AFTER_CREATE_MTC_TASK, 4));
        mtContexts.put(PARENT_AFTER_CREATE_MTC_TASK, after);

        Future<?> submit = executorService.submit(mtContextRunnable);
        submit.get();

        // child Inheritable
        assertEquals(3, task.copied.size());
        assertEquals(new FooPojo(PARENT_UNMODIFIED_IN_CHILD, 1), task.copied.get(PARENT_UNMODIFIED_IN_CHILD));
        assertEquals(new FooPojo(PARENT_MODIFIED_IN_CHILD + "1", 2), task.copied.get(PARENT_MODIFIED_IN_CHILD));
        assertEquals(new FooPojo(CHILD + 1, 3), task.copied.get(CHILD + 1));

        // child do not effect parent
        Map<String, Object> copied = copied(mtContexts);
        assertEquals(3, copied.size());
        assertEquals(new FooPojo(PARENT_UNMODIFIED_IN_CHILD, 1), copied.get(PARENT_UNMODIFIED_IN_CHILD));
        assertEquals(new FooPojo(PARENT_MODIFIED_IN_CHILD, 2), copied.get(PARENT_MODIFIED_IN_CHILD));
        assertEquals(new FooPojo(PARENT_AFTER_CREATE_MTC_TASK, 4), copied.get(PARENT_AFTER_CREATE_MTC_TASK));
    }
View Full Code Here

TOP

Related Classes of com.alibaba.mtc.testmodel.FooPojo

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.