-
Notifications
You must be signed in to change notification settings - Fork 613
/
AbstractReaderTest.java
64 lines (53 loc) · 3 KB
/
AbstractReaderTest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package org.infinispan.tools.store.migrator;
import static org.infinispan.tools.store.migrator.Element.CACHE_NAME;
import static org.infinispan.tools.store.migrator.Element.EXTERNALIZERS;
import static org.infinispan.tools.store.migrator.Element.MARSHALLER;
import static org.infinispan.tools.store.migrator.Element.SOURCE;
import static org.infinispan.tools.store.migrator.Element.TARGET;
import static org.infinispan.tools.store.migrator.Element.TYPE;
import static org.infinispan.tools.store.migrator.TestUtil.propKey;
import static org.testng.AssertJUnit.assertEquals;
import static org.testng.AssertJUnit.assertNotNull;
import java.util.Properties;
import org.infinispan.Cache;
import org.infinispan.configuration.cache.Configuration;
import org.infinispan.configuration.global.GlobalConfiguration;
import org.infinispan.configuration.global.GlobalConfigurationBuilder;
import org.infinispan.manager.DefaultCacheManager;
import org.infinispan.manager.EmbeddedCacheManager;
import org.infinispan.tools.store.migrator.marshaller.MarshallerType;
import org.testng.annotations.Test;
@Test(testName = "org.infinispan.tools.store.migrator.AbstractReaderTest", groups = "functional")
public abstract class AbstractReaderTest {
private static final String TEST_CACHE_NAME = "reader-test";
abstract public Configuration getTargetCacheConfig();
protected void configureStoreProperties(Properties properties, Element type) {
MarshallerType marshallerType = type == SOURCE ? MarshallerType.LEGACY : MarshallerType.CURRENT;
properties.put(propKey(type, CACHE_NAME), TEST_CACHE_NAME);
properties.put(propKey(type, MARSHALLER, TYPE), marshallerType.toString());
properties.put(propKey(type, MARSHALLER, EXTERNALIZERS), "256:" + TestUtil.TestObjectExternalizer.class.getName());
}
@Test
public void readerCompatibilityTest() throws Exception {
Properties properties = new Properties();
configureStoreProperties(properties, SOURCE);
configureStoreProperties(properties, TARGET);
// Read from the legacy LevelDB store and populate the new RocksDBStore using latest marshaller
new StoreMigrator(properties).run();
GlobalConfiguration globalConfig = new GlobalConfigurationBuilder()
.serialization().addAdvancedExternalizer(256, new TestUtil.TestObjectExternalizer())
.build();
Configuration config = getTargetCacheConfig();
// Create a new cache instance, with the required externalizers, to ensure that the new RocksDbStore can be
// loaded and contains all of the expected values.
EmbeddedCacheManager manager = new DefaultCacheManager(globalConfig, config);
Cache cache = manager.getCache(TEST_CACHE_NAME);
for (String key : TestUtil.TEST_MAP.keySet()) {
Object stored = cache.get(key);
assertNotNull(String.format("Key=%s", key), stored);
Object expected = TestUtil.TEST_MAP.get(key);
assertNotNull(String.format("Key=%s", key), stored);
assertEquals(expected, stored);
}
}
}