1 |
| |
2 |
| |
3 |
| |
4 |
| |
5 |
| |
6 |
| |
7 |
| package org.jboss.cache.loader; |
8 |
| |
9 |
| import junit.framework.Test; |
10 |
| import junit.framework.TestSuite; |
11 |
| import org.apache.derby.jdbc.EmbeddedXADataSource; |
12 |
| import org.jboss.cache.Fqn; |
13 |
| import org.jboss.cache.transaction.DummyTransactionManager; |
14 |
| |
15 |
| import javax.naming.Context; |
16 |
| import javax.naming.InitialContext; |
17 |
| import javax.naming.NameNotFoundException; |
18 |
| import java.util.Properties; |
19 |
| |
20 |
| |
21 |
| |
22 |
| |
23 |
| |
24 |
| |
25 |
| |
26 |
| |
27 |
| |
28 |
| |
29 |
| |
30 |
| |
31 |
| |
32 |
| public class JDBCCacheLoaderDerbyDSTest |
33 |
| extends CacheLoaderTestsBase |
34 |
| { |
35 |
| private String old_factory = null; |
36 |
| private final String FACTORY = "org.jboss.cache.transaction.DummyContextFactory"; |
37 |
| private final String JNDI_NAME = "java:/DerbyDS"; |
38 |
| |
39 |
60
| protected void configureCache() throws Exception
|
40 |
| { |
41 |
60
| old_factory = System.getProperty(Context.INITIAL_CONTEXT_FACTORY);
|
42 |
60
| System.setProperty(Context.INITIAL_CONTEXT_FACTORY, FACTORY);
|
43 |
60
| DummyTransactionManager.getInstance();
|
44 |
| |
45 |
60
| Context context = new InitialContext();
|
46 |
60
| try
|
47 |
| { |
48 |
60
| Object obj = context.lookup(JNDI_NAME);
|
49 |
60
| assertNull(JNDI_NAME + " not bound", obj);
|
50 |
| } |
51 |
| catch (NameNotFoundException n) |
52 |
| { |
53 |
| |
54 |
| } |
55 |
| |
56 |
60
| Properties prop = new Properties();
|
57 |
60
| try
|
58 |
| { |
59 |
60
| prop.load(this.getClass().getClassLoader().getResourceAsStream("cache-jdbc.properties"));
|
60 |
| } |
61 |
| catch (Exception e) |
62 |
| { |
63 |
0
| System.out.println("Error loading jdbc properties ");
|
64 |
| } |
65 |
| |
66 |
| |
67 |
60
| EmbeddedXADataSource ds = new EmbeddedXADataSource();
|
68 |
60
| ds.setDatabaseName("jbossdb");
|
69 |
60
| ds.setCreateDatabase("create");
|
70 |
60
| ds.setUser(prop.getProperty("cache.jdbc.user"));
|
71 |
| ; |
72 |
60
| ds.setPassword(prop.getProperty("cache.jdbc.password"));
|
73 |
| |
74 |
| |
75 |
60
| String props = "cache.jdbc.datasource =" + JNDI_NAME + "\n" +
|
76 |
| "cache.jdbc.node.type=" + prop.getProperty("cache.jdbc.node.type"); |
77 |
| |
78 |
| |
79 |
60
| cache.getConfiguration().setCacheLoaderConfig(getSingleCacheLoaderConfig("", "org.jboss.cache.loader.JDBCCacheLoader", props, false, true, false));
|
80 |
60
| cache.create();
|
81 |
| |
82 |
| |
83 |
60
| context.bind(JNDI_NAME, ds);
|
84 |
60
| assertNotNull(JNDI_NAME + " bound", context.lookup(JNDI_NAME));
|
85 |
| } |
86 |
| |
87 |
1
| public void testLargeObject()
|
88 |
| { |
89 |
1
| try
|
90 |
| { |
91 |
1
| String key = "LargeObj";
|
92 |
| |
93 |
1
| StringBuffer text = new StringBuffer("LargeObject");
|
94 |
1
| while (text.toString().getBytes().length < (1024 * 100))
|
95 |
| { |
96 |
14
| text.append(text);
|
97 |
| } |
98 |
1
| String initialValue = text.toString();
|
99 |
| |
100 |
1
| loader.remove(Fqn.fromString("/"));
|
101 |
| |
102 |
1
| Object retVal = loader.put(FQN, key, initialValue);
|
103 |
1
| assertNull(retVal);
|
104 |
1
| addDelay();
|
105 |
| |
106 |
1
| assertEquals(initialValue, (String) loader.get(FQN).get(key));
|
107 |
| |
108 |
1
| String updatedValue = initialValue.concat(("UpdatedValue"));
|
109 |
1
| retVal = loader.put(FQN, key, updatedValue);
|
110 |
1
| assertEquals(initialValue, (String) retVal);
|
111 |
1
| assertEquals(updatedValue, (String) loader.get(FQN).get(key));
|
112 |
| } |
113 |
| catch (Exception e) |
114 |
| { |
115 |
0
| fail(e.toString());
|
116 |
| } |
117 |
| } |
118 |
| |
119 |
1
| public void testTransactionRollback() throws Exception
|
120 |
| { |
121 |
| |
122 |
| } |
123 |
| |
124 |
1
| public void testIntegratedTransactionRollback() throws Exception
|
125 |
| { |
126 |
| |
127 |
| } |
128 |
| |
129 |
1
| public static Test suite()
|
130 |
| { |
131 |
1
| return new TestSuite(JDBCCacheLoaderDerbyDSTest.class);
|
132 |
| } |
133 |
| |
134 |
0
| public static void main(String[] args)
|
135 |
| { |
136 |
0
| junit.textui.TestRunner.run(suite());
|
137 |
| } |
138 |
| |
139 |
60
| protected void tearDown() throws Exception
|
140 |
| { |
141 |
60
| super.tearDown();
|
142 |
| |
143 |
60
| Context ctx = new InitialContext();
|
144 |
60
| ctx.unbind(JNDI_NAME);
|
145 |
60
| if (old_factory != null)
|
146 |
| { |
147 |
0
| System.setProperty(Context.INITIAL_CONTEXT_FACTORY, old_factory);
|
148 |
| } |
149 |
| else |
150 |
| { |
151 |
60
| System.getProperties().remove(Context.INITIAL_CONTEXT_FACTORY);
|
152 |
| } |
153 |
| } |
154 |
| } |