KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > test > testbeancluster > test > CacheInvalidationUnitTestCase


1 /*
2   * JBoss, Home of Professional Open Source
3   * Copyright 2005, JBoss Inc., and individual contributors as indicated
4   * by the @authors tag. See the copyright.txt in the distribution for a
5   * full listing of individual contributors.
6   *
7   * This is free software; you can redistribute it and/or modify it
8   * under the terms of the GNU Lesser General Public License as
9   * 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 JavaDoc;
25 import javax.naming.Context JavaDoc;
26 import javax.naming.InitialContext JavaDoc;
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: 37406 $
41  */

42 public class CacheInvalidationUnitTestCase extends JBossClusteredTestCase
43 {
44    public CacheInvalidationUnitTestCase(String JavaDoc name)
45    {
46       super(name);
47    }
48
49    public static Test suite() throws Exception JavaDoc
50    {
51       TestSuite suite = new TestSuite();
52       Test t1 = getDeploySetup(CacheInvalidationUnitTestCase.class,
53          "test-cif.ear");
54
55       suite.addTest(t1);
56
57       // Create an initializer for the test suite
58
DBSetup wrapper = new DBSetup(suite);
59       return wrapper;
60    }
61
62    public void testCacheInvalidation()
63       throws Exception JavaDoc
64    {
65       log.info("+++ testCacheInvalidation");
66
67       // Connect to the server0 JNDI
68
String JavaDoc[] urls = getNamingURLs();
69       Properties JavaDoc env1 = new Properties JavaDoc();
70       env1.setProperty(Context.INITIAL_CONTEXT_FACTORY,
71          "org.jnp.interfaces.NamingContextFactory");
72       env1.setProperty(Context.PROVIDER_URL, urls[0]);
73       InitialContext JavaDoc ctx1 = new InitialContext JavaDoc(env1);
74
75       SessionToEntityHome home1 =
76          (SessionToEntityHome) ctx1.lookup("cif.StatefulSession");
77       AComplexPK key = new AComplexPK(true, 0, 0, 0, "testCacheInvalidation");
78       SessionToEntity bean1 = home1.create(key);
79       String JavaDoc msg = bean1.createEntity();
80       log.info("create#1, "+msg);
81       // Call accessEntity twice to validate data is consistent on both nodes
82
NodeAnswer answer1 = bean1.accessEntity();
83       log.info("Answer1: "+answer1);
84       NodeAnswer answer2 = bean1.accessEntity();
85       log.info("Answer2: "+answer2);
86       assertTrue("accessCount == 2", bean1.getAccessCount() == 2);
87       assertTrue("answer1.nodeId != answer2.nodeId",
88          answer1.nodeId.equals(answer2.nodeId) == false);
89
90       // Call validateAccessCount twice to validate data is consistent on both nodes
91
answer1 = bean1.validateAccessCount(2);
92       log.info(answer1);
93       answer2 = bean1.validateAccessCount(2);
94       log.info(answer2);
95       assertTrue("answer1.nodeId != answer2.nodeId",
96          answer1.nodeId.equals(answer2.nodeId) == false);
97       bean1.remove();
98    }
99
100 }
101
Popular Tags