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 |
120
| public JDBCCacheLoaderTest(String name)
|
32 |
| { |
33 |
120
| super(name);
|
34 |
| } |
35 |
| |
36 |
60
| protected void configureCache() throws Exception
|
37 |
| { |
38 |
60
| Properties prop = getProperties();
|
39 |
| |
40 |
60
| 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"); |
45 |
| |
46 |
60
| cache.getConfiguration().setCacheLoaderConfig(getSingleCacheLoaderConfig("",
|
47 |
| "org.jboss.cache.loader.JDBCCacheLoader", props, false, true, false)); |
48 |
| } |
49 |
| |
50 |
2
| public void testLargeObject()
|
51 |
| { |
52 |
2
| try
|
53 |
| { |
54 |
2
| String key = "LargeObj";
|
55 |
| |
56 |
2
| StringBuffer text = new StringBuffer("LargeObject");
|
57 |
2
| while (text.toString().getBytes().length < (1024 * 100))
|
58 |
| { |
59 |
28
| text.append(text);
|
60 |
| } |
61 |
2
| String initialValue = text.toString();
|
62 |
| |
63 |
2
| loader.remove(Fqn.fromString("/"));
|
64 |
| |
65 |
2
| Object retVal = loader.put(FQN, key, initialValue);
|
66 |
2
| assertNull(retVal);
|
67 |
2
| addDelay();
|
68 |
| |
69 |
2
| assertEquals(initialValue, (String) loader.get(FQN).get(key));
|
70 |
| |
71 |
2
| String updatedValue = initialValue.concat(("UpdatedValue"));
|
72 |
2
| retVal = loader.put(FQN, key, updatedValue);
|
73 |
2
| assertEquals(initialValue, (String) retVal);
|
74 |
2
| assertEquals(updatedValue, (String) loader.get(FQN).get(key));
|
75 |
| } catch (Exception e) |
76 |
| { |
77 |
0
| fail(e.toString());
|
78 |
| } |
79 |
| } |
80 |
| |
81 |
120
| protected Properties getProperties() throws Exception
|
82 |
| { |
83 |
120
| Properties properties = new Properties();
|
84 |
120
| try
|
85 |
| { |
86 |
120
| properties.load(this.getClass().getClassLoader().getResourceAsStream("cache-jdbc.properties"));
|
87 |
120
| return properties;
|
88 |
| } |
89 |
| catch (Exception e) |
90 |
| { |
91 |
0
| throw new Exception("Error loading jdbc properties ", e);
|
92 |
| } |
93 |
| } |
94 |
| |
95 |
1
| public static Test suite()
|
96 |
| { |
97 |
1
| return new TestSuite(JDBCCacheLoaderTest.class);
|
98 |
| } |
99 |
| } |