KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > cache > pojo > statetransfer > ReplicatedTest


1 /*
2  * JBoss, Home of Professional Open Source.
3  * Copyright 2006, Red Hat Middleware LLC, and individual contributors
4  * as indicated by the @author tags. See the copyright.txt file in the
5  * distribution for a 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
23 package org.jboss.cache.pojo.statetransfer;
24
25 import junit.framework.Test;
26 import junit.framework.TestCase;
27 import junit.framework.TestSuite;
28 import org.apache.commons.logging.Log;
29 import org.apache.commons.logging.LogFactory;
30 import org.jboss.cache.CacheImpl;
31 import org.jboss.cache.pojo.PojoCache;
32 import org.jboss.cache.pojo.PojoCacheFactory;
33 import org.jboss.cache.pojo.test.Person;
34 import org.jboss.cache.pojo.test.Student;
35
36 /**
37  * Simple replicated test for state transfer
38  *
39  * @author Ben Wang
40  */

41 public class ReplicatedTest extends TestCase
42 {
43    Log log = LogFactory.getLog(ReplicatedTest.class);
44    PojoCache cache, cache1;
45
46
47    public ReplicatedTest(String JavaDoc name)
48    {
49       super(name);
50    }
51
52    protected void setUp() throws Exception JavaDoc
53    {
54       super.setUp();
55       log.info("setUp() ....");
56    }
57
58    protected void tearDown() throws Exception JavaDoc
59    {
60       super.tearDown();
61       cache.stop();
62       cache1.stop();
63    }
64
65 // public void testDummy() {}
66

67    private Person createPerson(String JavaDoc id, String JavaDoc name, int age)
68    {
69       Person p = new Person();
70       p.setName(name);
71       p.setAge(age);
72       cache.attach(id, p);
73       return p;
74    }
75
76    private Student createStudent(String JavaDoc id, String JavaDoc name, int age, String JavaDoc grade)
77    {
78       Student p = new Student();
79       p.setName(name);
80       p.setAge(age);
81       p.setYear(grade);
82       cache.attach(id, p);
83       return p;
84    }
85
86    public void testSimple() throws Exception JavaDoc
87    {
88       String JavaDoc configFile = "META-INF/replSync-service.xml";
89       boolean toStart = true;
90       cache = PojoCacheFactory.createCache(configFile, toStart);
91       Person ben = createPerson("/person/test1", "Ben Wang", 40);
92
93       System.out.println("\n*** I ***");
94       System.out.println(((CacheImpl) cache.getCache()).printDetails());
95       cache1 = PojoCacheFactory.createCache(configFile, toStart);
96       cache1.start();
97
98       System.out.println("\n*** II ***");
99       System.out.println(((CacheImpl) cache1.getCache()).printDetails());
100
101       Person p = (Person) cache1.find("/person/test1");
102
103       log.info("testSimple() ....");
104       assertEquals("Ben Wang", ben.getName());
105       assertEquals("Ben Wang", ((Person) cache1.find("/person/test1")).getName());
106       cache.detach("/person/test1");
107    }
108
109    public static Test suite() throws Exception JavaDoc
110    {
111       return new TestSuite(ReplicatedTest.class);
112    }
113
114
115    public static void main(String JavaDoc[] args) throws Exception JavaDoc
116    {
117       junit.textui.TestRunner.run(suite());
118    }
119
120 }
121
Popular Tags