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.jboss.cache.Fqn; |
12 |
| |
13 |
| import java.util.Properties; |
14 |
| |
15 |
| |
16 |
| |
17 |
| |
18 |
| |
19 |
| |
20 |
| |
21 |
| |
22 |
| |
23 |
| |
24 |
| |
25 |
| |
26 |
| |
27 |
| |
28 |
| |
29 |
| public class JDBCCacheLoaderTest extends CacheLoaderTestsBase |
30 |
| { |
31 |
126
| public JDBCCacheLoaderTest(String name)
|
32 |
| { |
33 |
126
| super(name);
|
34 |
| } |
35 |
| |
36 |
63
| protected void configureCache() throws Exception
|
37 |
| { |
38 |
63
| Properties prop = getProperties();
|
39 |
| |
40 |
63
| String props = "cache.jdbc.driver =" + prop.getProperty("cache.jdbc.driver") + "\n" +
|
41 |
| "cache.jdbc.url=" + prop.getProperty("cache.jdbc.url") + "\n" + |
42 |
| "cache.jdbc.user=" + prop.getProperty("cache.jdbc.user") + "\n" + |
43 |
| "cache.jdbc.password=" + prop.getProperty("cache.jdbc.password") + "\n" + |
44 |
| "cache.jdbc.node.type=" + prop.getProperty("cache.jdbc.node.type") + "\n" + |
45 |
| "cache.jdbc.sql-concat=" + prop.getProperty("cache.jdbc.sql-concat"); |
46 |
| |
47 |
63
| cache.getConfiguration().setCacheLoaderConfig(getSingleCacheLoaderConfig("",
|
48 |
| "org.jboss.cache.loader.JDBCCacheLoader", props, false, true, false)); |
49 |
| } |
50 |
| |
51 |
2
| public void testLargeObject()
|
52 |
| { |
53 |
2
| try
|
54 |
| { |
55 |
2
| String key = "LargeObj";
|
56 |
| |
57 |
2
| StringBuffer text = new StringBuffer("LargeObject");
|
58 |
2
| while (text.toString().getBytes().length < (1024 * 100))
|
59 |
| { |
60 |
28
| text.append(text);
|
61 |
| } |
62 |
2
| String initialValue = text.toString();
|
63 |
| |
64 |
2
| loader.remove(Fqn.fromString("/"));
|
65 |
| |
66 |
2
| Object retVal = loader.put(FQN, key, initialValue);
|
67 |
2
| assertNull(retVal);
|
68 |
2
| addDelay();
|
69 |
| |
70 |
2
| assertEquals(initialValue, (String) loader.get(FQN).get(key));
|
71 |
| |
72 |
2
| String updatedValue = initialValue.concat(("UpdatedValue"));
|
73 |
2
| retVal = loader.put(FQN, key, updatedValue);
|
74 |
2
| assertEquals(initialValue, (String) retVal);
|
75 |
2
| assertEquals(updatedValue, (String) loader.get(FQN).get(key));
|
76 |
| } catch (Exception e) |
77 |
| { |
78 |
0
| fail(e.toString());
|
79 |
| } |
80 |
| } |
81 |
| |
82 |
126
| protected Properties getProperties() throws Exception
|
83 |
| { |
84 |
126
| Properties properties = new Properties();
|
85 |
126
| try
|
86 |
| { |
87 |
126
| properties.load(this.getClass().getClassLoader().getResourceAsStream("cache-jdbc.properties"));
|
88 |
126
| return properties;
|
89 |
| } |
90 |
| catch (Exception e) |
91 |
| { |
92 |
0
| throw new Exception("Error loading jdbc properties ", e);
|
93 |
| } |
94 |
| } |
95 |
| |
96 |
2
| public void testRootIsCreated() throws Exception
|
97 |
| { |
98 |
2
| loader.put(Fqn.fromString("/a/b/c"), "a", "b");
|
99 |
2
| assertTrue(loader.exists(Fqn.ROOT));
|
100 |
| } |
101 |
| |
102 |
1
| public static Test suite()
|
103 |
| { |
104 |
1
| return new TestSuite(JDBCCacheLoaderTest.class);
|
105 |
| } |
106 |
| } |