use of org.infinispan.persistence.keymappers.TwoWayKey2StringMapper in project wildfly by wildfly.
the class OrdinalKeyFormatMapperTestCase method testSinglePadding.
@Test
public void testSinglePadding() {
TwoWayKey2StringMapper mapper = new IndexedKeyFormatMapper(createPersistenceList(16));
Assert.assertTrue(mapper.isSupportedType(Type.TYPE00.getClass()));
Assert.assertTrue(mapper.isSupportedType(Type.TYPE15.getClass()));
Assert.assertFalse(mapper.isSupportedType(Type.TYPE16.getClass()));
Assert.assertFalse(mapper.isSupportedType(Type.TYPE17.getClass()));
String result = mapper.getStringMapping(Type.TYPE00);
Assert.assertSame(Type.TYPE00, mapper.getKeyMapping(result));
Assert.assertEquals("0TYPE00", result);
result = mapper.getStringMapping(Type.TYPE15);
Assert.assertSame(Type.TYPE15, mapper.getKeyMapping(result));
Assert.assertEquals("FTYPE15", result);
}
use of org.infinispan.persistence.keymappers.TwoWayKey2StringMapper in project wildfly by wildfly.
the class OrdinalKeyFormatMapperTestCase method testDoublePadding.
@Test
public void testDoublePadding() {
TwoWayKey2StringMapper mapper = new IndexedKeyFormatMapper(createPersistenceList(17));
Assert.assertTrue(mapper.isSupportedType(Type.TYPE00.getClass()));
Assert.assertTrue(mapper.isSupportedType(Type.TYPE15.getClass()));
Assert.assertTrue(mapper.isSupportedType(Type.TYPE16.getClass()));
Assert.assertFalse(mapper.isSupportedType(Type.TYPE17.getClass()));
String result = mapper.getStringMapping(Type.TYPE00);
Assert.assertSame(Type.TYPE00, mapper.getKeyMapping(result));
Assert.assertEquals("00TYPE00", result);
result = mapper.getStringMapping(Type.TYPE15);
Assert.assertSame(Type.TYPE15, mapper.getKeyMapping(result));
Assert.assertEquals("0FTYPE15", result);
result = mapper.getStringMapping(Type.TYPE16);
Assert.assertSame(Type.TYPE16, mapper.getKeyMapping(result));
Assert.assertEquals("10TYPE16", result);
}
use of org.infinispan.persistence.keymappers.TwoWayKey2StringMapper in project wildfly by wildfly.
the class SimpleKeyFormatMapperTestCase method test.
@Test
public void test() {
KeyFormat<Object> keyFormat = mock(KeyFormat.class);
TwoWayKey2StringMapper mapper = new SimpleKeyFormatMapper(keyFormat);
Object key = new Object();
String formatted = "foo";
when(keyFormat.getTargetClass()).thenReturn(Object.class);
when(keyFormat.format(key)).thenReturn(formatted);
when(keyFormat.parse(formatted)).thenReturn(key);
Assert.assertSame(formatted, mapper.getStringMapping(key));
Assert.assertSame(key, mapper.getKeyMapping(formatted));
Assert.assertTrue(mapper.isSupportedType(Object.class));
Assert.assertFalse(mapper.isSupportedType(Integer.class));
}
use of org.infinispan.persistence.keymappers.TwoWayKey2StringMapper in project wildfly by wildfly.
the class KeyMapperTestCase method test.
@Test
public void test() {
TwoWayKey2StringMapper mapper = new KeyMapper();
Assert.assertTrue(mapper.isSupportedType(SessionCreationMetaDataKey.class));
Assert.assertTrue(mapper.isSupportedType(SessionAccessMetaDataKey.class));
Assert.assertTrue(mapper.isSupportedType(SessionAttributesKey.class));
Assert.assertTrue(mapper.isSupportedType(SessionAttributeNamesKey.class));
Assert.assertTrue(mapper.isSupportedType(SessionAttributeKey.class));
Assert.assertTrue(mapper.isSupportedType(AuthenticationKey.class));
Assert.assertTrue(mapper.isSupportedType(CoarseSessionsKey.class));
Set<String> formatted = new HashSet<>();
String id = "ABC123";
SessionCreationMetaDataKey creationMetaDataKey = new SessionCreationMetaDataKey(id);
String formattedCreationMetaDataKey = mapper.getStringMapping(creationMetaDataKey);
Assert.assertEquals(creationMetaDataKey, mapper.getKeyMapping(formattedCreationMetaDataKey));
Assert.assertTrue(formatted.add(formattedCreationMetaDataKey));
SessionAccessMetaDataKey accessMetaDataKey = new SessionAccessMetaDataKey(id);
String formattedAccessMetaDataKey = mapper.getStringMapping(accessMetaDataKey);
Assert.assertEquals(accessMetaDataKey, mapper.getKeyMapping(formattedAccessMetaDataKey));
Assert.assertTrue(formatted.add(formattedAccessMetaDataKey));
SessionAttributesKey attributesKey = new SessionAttributesKey(id);
String formattedAttributesKey = mapper.getStringMapping(attributesKey);
Assert.assertEquals(attributesKey, mapper.getKeyMapping(formattedAttributesKey));
Assert.assertTrue(formatted.add(formattedAttributesKey));
SessionAttributeNamesKey attributeNamesKey = new SessionAttributeNamesKey(id);
String formattedAttributeNamesKey = mapper.getStringMapping(attributeNamesKey);
Assert.assertEquals(attributeNamesKey, mapper.getKeyMapping(formattedAttributeNamesKey));
Assert.assertTrue(formatted.add(formattedAttributeNamesKey));
for (int i = 0; i < 10; ++i) {
SessionAttributeKey attributeKey = new SessionAttributeKey(id, i);
String formattedAttributeKey = mapper.getStringMapping(attributeKey);
Assert.assertEquals(attributeKey, mapper.getKeyMapping(formattedAttributeKey));
Assert.assertTrue(formatted.add(formattedAttributeKey));
}
AuthenticationKey authKey = new AuthenticationKey(id);
String formattedAuthKey = mapper.getStringMapping(authKey);
Assert.assertEquals(authKey, mapper.getKeyMapping(formattedAuthKey));
Assert.assertTrue(formatted.add(formattedAuthKey));
CoarseSessionsKey sessionsKey = new CoarseSessionsKey(id);
String formattedSessionsKey = mapper.getStringMapping(sessionsKey);
Assert.assertEquals(sessionsKey, mapper.getKeyMapping(formattedSessionsKey));
Assert.assertTrue(formatted.add(formattedSessionsKey));
}
use of org.infinispan.persistence.keymappers.TwoWayKey2StringMapper in project wildfly by wildfly.
the class KeyMapperTestCase method test.
@Test
public void test() {
TwoWayKey2StringMapper mapper = new KeyMapper();
Assert.assertTrue(mapper.isSupportedType(InfinispanBeanKey.class));
Assert.assertTrue(mapper.isSupportedType(InfinispanBeanGroupKey.class));
Set<String> formatted = new HashSet<>();
SessionID id = new UUIDSessionID(UUID.randomUUID());
BeanKey<SessionID> beanKey = new InfinispanBeanKey<>(id);
String formattedBeanKey = mapper.getStringMapping(beanKey);
Assert.assertEquals(beanKey, mapper.getKeyMapping(formattedBeanKey));
Assert.assertTrue(formatted.add(formattedBeanKey));
BeanGroupKey<SessionID> beanGroupKey = new InfinispanBeanGroupKey<>(id);
String formattedBeanGroupKey = mapper.getStringMapping(beanGroupKey);
Assert.assertEquals(beanGroupKey, mapper.getKeyMapping(formattedBeanGroupKey));
Assert.assertTrue(formatted.add(formattedBeanGroupKey));
}
Aggregations