Package org.jboss.cache.optimistic

Source Code of org.jboss.cache.optimistic.NodeInterceptorTransactionTest

/*
* Created on 17-Feb-2005
*
*
*
*/
package org.jboss.cache.optimistic;

import org.jboss.cache.TreeCache;
import org.jboss.cache.interceptors.Interceptor;
import org.jboss.cache.interceptors.OptimisticCreateIfNotExistsInterceptor;
import org.jboss.cache.interceptors.OptimisticNodeInterceptor;

/**
* @author xenephon
*/
public class NodeInterceptorTransactionTest extends AbstractOptimisticTestCase
{

    /**
     * @param name
     */
    public NodeInterceptorTransactionTest(String name)
    {
        super(name);

    }

    public void testNoTransactionCRUDMethod() throws Exception
    {

        TestListener listener = new TestListener();
        final TreeCache cache = createCacheWithListener(listener);

        Interceptor interceptor = new OptimisticCreateIfNotExistsInterceptor();
        interceptor.setCache(cache);
        Interceptor nodeInterceptor = new OptimisticNodeInterceptor();
        nodeInterceptor.setCache(cache);
        MockInterceptor dummy = new MockInterceptor();
        dummy.setCache(cache);

        interceptor.setNext(nodeInterceptor);
        nodeInterceptor.setNext(dummy);

        cache.setInterceptorChain(interceptor);

        try
        {
            cache.put("/one/two", "key1", new Object());
            fail();
        }
        catch (Throwable t)
        {

            assertTrue(true);
        }
        assertEquals(null, dummy.getCalled());
        cache.stopService();
    }

    public void testNoTransactionGetMethod() throws Exception
    {

        TestListener listener = new TestListener();
        final TreeCache cache = createCacheWithListener(listener);

        Interceptor interceptor = new OptimisticCreateIfNotExistsInterceptor();
        interceptor.setCache(cache);
        Interceptor nodeInterceptor = new OptimisticNodeInterceptor();
        nodeInterceptor.setCache(cache);
        MockInterceptor dummy = new MockInterceptor();
        dummy.setCache(cache);

        interceptor.setNext(nodeInterceptor);
        nodeInterceptor.setNext(dummy);

        cache.setInterceptorChain(interceptor);

        boolean fail = false;
        try
        {
            assertEquals(null, cache.get("/one/two", "key1"));
        }
        catch (Exception e)
        {
            fail = true;
        }
        assertTrue(fail);
        assertEquals(null, dummy.getCalled());
        cache.stopService();
    }


}
TOP

Related Classes of org.jboss.cache.optimistic.NodeInterceptorTransactionTest

TOP
Copyright © 2018 www.massapi.com. 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.