KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > cache > loader > TcpCacheLoaderTest


1 package org.jboss.cache.loader;
2
3 import junit.framework.Test;
4 import junit.framework.TestSuite;
5 import org.jboss.cache.loader.tcp.TcpCacheServer;
6 import org.jboss.cache.misc.TestingUtil;
7
8 /**
9  * Tests the TcpDelegatingCacheLoader
10  *
11  * @author Bela Ban
12  * @version $Id: TcpCacheLoaderTest.java,v 1.12 2006/12/20 13:40:24 msurtani Exp $
13  */

14 public class TcpCacheLoaderTest extends CacheLoaderTestsBase
15 {
16    static TcpCacheServer cache_server = null;
17
18    static
19    {
20       Thread JavaDoc runner = new Thread JavaDoc()
21       {
22          public void run()
23          {
24             try
25             {
26                System.out.println("Starting TcpCacheServer");
27                cache_server = new TcpCacheServer();
28                cache_server.setBindAddress("127.0.0.1");
29                cache_server.setPort(12121);
30                cache_server.setConfig("META-INF/local-service.xml"); // must be in classpath (./etc/META-INF)
31
cache_server.create();
32                cache_server.start();
33             }
34             catch (Exception JavaDoc ex)
35             {
36                ex.printStackTrace();
37             }
38          }
39       };
40
41       Runtime.getRuntime().addShutdownHook(new Thread JavaDoc()
42       {
43          public void run()
44          {
45             if (cache_server != null)
46             {
47                System.out.println("Stopping TcpCacheServer");
48                cache_server.stop();
49             }
50          }
51       });
52
53       runner.start();
54    }
55
56    public void testPartialLoadAndStore()
57    {
58       // do nothing
59
}
60
61    public void testBuddyBackupStore()
62    {
63       // do nothing
64
}
65
66
67    protected void configureCache() throws Exception JavaDoc
68    {
69       cache.getConfiguration().setCacheLoaderConfig(getSingleCacheLoaderConfig("",
70               "org.jboss.cache.loader.TcpDelegatingCacheLoader",
71               "host=127.0.0.1\nport=12121", false, true, false));
72
73       // give the tcp cache server time to start up
74
TestingUtil.sleepThread(2000);
75    }
76
77
78    public static Test suite()
79    {
80       return new TestSuite(TcpCacheLoaderTest.class);
81    }
82
83
84    public static void main(String JavaDoc[] args)
85    {
86       junit.textui.TestRunner.run(suite());
87    }
88
89 }
Popular Tags