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 |
62
| protected void configureCache() throws Exception
|
40 |
| { |
41 |
62
| old_factory = System.getProperty(Context.INITIAL_CONTEXT_FACTORY);
|
42 |
62
| System.setProperty(Context.INITIAL_CONTEXT_FACTORY, FACTORY);
|
43 |
62
| DummyTransactionManager.getInstance();
|
44 |
| |
45 |
62
| Context context = new InitialContext();
|
46 |
62
| try
|
47 |
| { |
48 |
62
| Object obj = context.lookup(JNDI_NAME);
|
49 |
62
| assertNull(JNDI_NAME + " not bound", obj);
|
50 |
| } |
51 |
| catch (NameNotFoundException n) |
52 |
| { |
53 |
| |
54 |
| } |
55 |
| |
56 |
62
| Properties prop = new Properties();
|
57 |
62
| try
|
58 |
| { |
59 |
62
| 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 |
62
| EmbeddedXADataSource ds = new EmbeddedXADataSource();
|
68 |
62
| ds.setDatabaseName("jbossdb");
|
69 |
62
| ds.setCreateDatabase("create");
|
70 |
62
| ds.setUser(prop.getProperty("cache.jdbc.user"));
|
71 |
| ; |
72 |
62
| ds.setPassword(prop.getProperty("cache.jdbc.password"));
|
73 |
| |
74 |
| |
75 |
62
| String props = "cache.jdbc.datasource =" + JNDI_NAME + "\n" +
|
76 |
| "cache.jdbc.node.type=" + prop.getProperty("cache.jdbc.node.type") + "\n" + |
77 |
| "cache.jdbc.sql-concat= 1 || 2"; |
78 |
| |
79 |
| |
80 |
62
| cache.getConfiguration().setCacheLoaderConfig(getSingleCacheLoaderConfig("", "org.jboss.cache.loader.JDBCCacheLoader", props, false, true, false));
|
81 |
62
| cache.create();
|
82 |
| |
83 |
| |
84 |
62
| context.bind(JNDI_NAME, ds);
|
85 |
62
| assertNotNull(JNDI_NAME + " bound", context.lookup(JNDI_NAME));
|
86 |
| } |
87 |
| |
88 |
1
| public void testLargeObject()
|
89 |
| { |
90 |
1
| try
|
91 |
| { |
92 |
1
| String key = "LargeObj";
|
93 |
| |
94 |
1
| StringBuffer text = new StringBuffer("LargeObject");
|
95 |
1
| while (text.toString().getBytes().length < (1024 * 100))
|
96 |
| { |
97 |
14
| text.append(text);
|
98 |
| } |
99 |
1
| String initialValue = text.toString();
|
100 |
| |
101 |
1
| loader.remove(Fqn.fromString("/"));
|
102 |
| |
103 |
1
| Object retVal = loader.put(FQN, key, initialValue);
|
104 |
1
| assertNull(retVal);
|
105 |
1
| addDelay();
|
106 |
| |
107 |
1
| assertEquals(initialValue, (String) loader.get(FQN).get(key));
|
108 |
| |
109 |
1
| String updatedValue = initialValue.concat(("UpdatedValue"));
|
110 |
1
| retVal = loader.put(FQN, key, updatedValue);
|
111 |
1
| assertEquals(initialValue, (String) retVal);
|
112 |
1
| assertEquals(updatedValue, (String) loader.get(FQN).get(key));
|
113 |
| } |
114 |
| catch (Exception e) |
115 |
| { |
116 |
0
| fail(e.toString());
|
117 |
| } |
118 |
| } |
119 |
| |
120 |
1
| public void testTransactionRollback() throws Exception
|
121 |
| { |
122 |
| |
123 |
| } |
124 |
| |
125 |
1
| public void testIntegratedTransactionRollback() throws Exception
|
126 |
| { |
127 |
| |
128 |
| } |
129 |
| |
130 |
1
| public static Test suite()
|
131 |
| { |
132 |
1
| return new TestSuite(JDBCCacheLoaderDerbyDSTest.class);
|
133 |
| } |
134 |
| |
135 |
0
| public static void main(String[] args)
|
136 |
| { |
137 |
0
| junit.textui.TestRunner.run(suite());
|
138 |
| } |
139 |
| |
140 |
62
| protected void tearDown() throws Exception
|
141 |
| { |
142 |
62
| super.tearDown();
|
143 |
| |
144 |
62
| Context ctx = new InitialContext();
|
145 |
62
| ctx.unbind(JNDI_NAME);
|
146 |
62
| if (old_factory != null)
|
147 |
| { |
148 |
0
| System.setProperty(Context.INITIAL_CONTEXT_FACTORY, old_factory);
|
149 |
| } |
150 |
| else |
151 |
| { |
152 |
62
| System.getProperties().remove(Context.INITIAL_CONTEXT_FACTORY);
|
153 |
| } |
154 |
| } |
155 |
| } |