01: /*
02: * JBoss, Home of Professional Open Source.
03: * Copyright 2006, Red Hat Middleware LLC, and individual contributors
04: * as indicated by the @author tags. See the copyright.txt file in the
05: * distribution for a full listing of individual contributors.
06: *
07: * This is free software; you can redistribute it and/or modify it
08: * under the terms of the GNU Lesser General Public License as
09: * published by the Free Software Foundation; either version 2.1 of
10: * the License, or (at your option) any later version.
11: *
12: * This software is distributed in the hope that it will be useful,
13: * but WITHOUT ANY WARRANTY; without even the implied warranty of
14: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15: * Lesser General Public License for more details.
16: *
17: * You should have received a copy of the GNU Lesser General Public
18: * License along with this software; if not, write to the Free
19: * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20: * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21: */
22: package org.jboss.test.testbeancluster.test;
23:
24: import java.util.Properties;
25: import javax.naming.Context;
26: import javax.naming.InitialContext;
27:
28: import junit.framework.Test;
29: import junit.framework.TestSuite;
30:
31: import org.jboss.test.JBossClusteredTestCase;
32: import org.jboss.test.testbean.interfaces.AComplexPK;
33: import org.jboss.test.testbeancluster.interfaces.SessionToEntityHome;
34: import org.jboss.test.testbeancluster.interfaces.SessionToEntity;
35: import org.jboss.test.testbeancluster.interfaces.NodeAnswer;
36:
37: /** Tests of the clustering cache invalidation framework
38: *
39: * @author Scott.Stark@jboss.org
40: * @version $Revision: 57211 $
41: */
42: public class CacheInvalidationUnitTestCase extends
43: JBossClusteredTestCase {
44: public CacheInvalidationUnitTestCase(String name) {
45: super (name);
46: }
47:
48: public static Test suite() throws Exception {
49: TestSuite suite = new TestSuite();
50: Test t1 = getDeploySetup(CacheInvalidationUnitTestCase.class,
51: "test-cif.ear");
52:
53: suite.addTest(t1);
54:
55: // Create an initializer for the test suite
56: DBSetup wrapper = new DBSetup(suite);
57: return wrapper;
58: }
59:
60: public void testCacheInvalidation() throws Exception {
61: log.info("+++ testCacheInvalidation");
62:
63: // Connect to the server0 JNDI
64: String[] urls = getNamingURLs();
65: Properties env1 = new Properties();
66: env1.setProperty(Context.INITIAL_CONTEXT_FACTORY,
67: "org.jnp.interfaces.NamingContextFactory");
68: env1.setProperty(Context.PROVIDER_URL, urls[0]);
69: InitialContext ctx1 = new InitialContext(env1);
70:
71: SessionToEntityHome home1 = (SessionToEntityHome) ctx1
72: .lookup("cif.StatefulSession");
73: AComplexPK key = new AComplexPK(true, 0, 0, 0,
74: "testCacheInvalidation");
75: SessionToEntity bean1 = home1.create(key);
76: String msg = bean1.createEntity();
77: log.info("create#1, " + msg);
78: // Call accessEntity twice to validate data is consistent on both nodes
79: NodeAnswer answer1 = bean1.accessEntity();
80: log.info("Answer1: " + answer1);
81: NodeAnswer answer2 = bean1.accessEntity();
82: log.info("Answer2: " + answer2);
83: assertTrue("accessCount == 2", bean1.getAccessCount() == 2);
84: assertTrue("answer1.nodeId != answer2.nodeId", answer1.nodeId
85: .equals(answer2.nodeId) == false);
86:
87: // Call validateAccessCount twice to validate data is consistent on both nodes
88: answer1 = bean1.validateAccessCount(2);
89: log.info(answer1);
90: answer2 = bean1.validateAccessCount(2);
91: log.info(answer2);
92: assertTrue("answer1.nodeId != answer2.nodeId", answer1.nodeId
93: .equals(answer2.nodeId) == false);
94: bean1.remove();
95: }
96:
97: }
|