use of com.zimbra.cs.ephemeral.InMemoryEphemeralStore in project zm-mailbox by Zimbra.
the class MigrateAttributesTest method testAttributeMigration.
/*
* Test end-to-end AttributeMigration
*/
@Test
public void testAttributeMigration() throws Exception {
EphemeralStore destination = EphemeralStore.getFactory().getStore();
EntrySource source = new DummyEntrySource(acct);
Multimap<String, Object> deletedAttrs = LinkedListMultimap.create();
List<String> attrsToMigrate = Arrays.asList(new String[] { Provisioning.A_zimbraAuthTokens, Provisioning.A_zimbraCsrfTokenData, Provisioning.A_zimbraLastLogonTimestamp });
//DummyMigrationCallback will store attributes in InMemoryEphemeralStore, and track deletions in deletedAttrs map
MigrationCallback callback = new DummyMigrationCallback(destination, deletedAttrs);
AttributeMigration migration = new AttributeMigration(attrsToMigrate, source, callback, null);
//disable running in separate thread
//run migration
migration.migrateAllAccounts();
EphemeralLocation location = new LdapEntryLocation(acct);
EphemeralResult result = destination.get(new EphemeralKey(Provisioning.A_zimbraAuthTokens, "1234"), location);
assertEquals("server_1", result.getValue());
result = destination.get(new EphemeralKey(Provisioning.A_zimbraAuthTokens, "5678"), location);
assertEquals("server_2", result.getValue());
result = destination.get(new EphemeralKey(Provisioning.A_zimbraCsrfTokenData, "crumb1"), location);
assertEquals("data1", result.getValue());
result = destination.get(new EphemeralKey(Provisioning.A_zimbraCsrfTokenData, "crumb2"), location);
assertEquals("data2", result.getValue());
result = destination.get(new EphemeralKey(Provisioning.A_zimbraLastLogonTimestamp), location);
assertEquals("currentdate", result.getValue());
Collection<Object> deleted = deletedAttrs.get(Provisioning.A_zimbraAuthTokens);
assertTrue(deleted.contains(authToken1));
assertTrue(deleted.contains(authToken2));
deleted = deletedAttrs.get(Provisioning.A_zimbraCsrfTokenData);
assertTrue(deleted.contains(csrfToken1));
assertTrue(deleted.contains(csrfToken2));
deleted = deletedAttrs.get(Provisioning.A_zimbraLastLogonTimestamp);
assertTrue(deleted.contains(lastLogon));
}
use of com.zimbra.cs.ephemeral.InMemoryEphemeralStore in project zm-mailbox by Zimbra.
the class MigrateAttributesTest method testFallbackEphemeralStoreWhenMigrating.
@Test
public void testFallbackEphemeralStoreWhenMigrating() throws Exception {
EphemeralStore destination = EphemeralStore.getFactory().getStore();
EntrySource source = new DummyEntrySource(acct);
Multimap<String, Object> deletedAttrs = LinkedListMultimap.create();
List<String> attrsToMigrate = Arrays.asList(new String[] { Provisioning.A_zimbraAuthTokens, Provisioning.A_zimbraCsrfTokenData, Provisioning.A_zimbraLastLogonTimestamp });
//DummyMigrationCallback will store attributes in InMemoryEphemeralStore, and track deletions in deletedAttrs map
MigrationCallback callback = new DummyMigrationCallback(destination, deletedAttrs);
AttributeMigration migration = new AttributeMigration(attrsToMigrate, source, callback, null);
migration.beginMigration();
//set to in-memory backend because fallback won't be enabled with default LDAP backend
EphemeralStore.setFactory(InMemoryEphemeralStore.Factory.class);
Factory factory = EphemeralStore.getFactory();
EphemeralStore store = factory.getStore();
//in-memory backend will be wrapped in a FallbackEphemeralStore, with LDAP as the fallback
assertTrue(store instanceof FallbackEphemeralStore);
FallbackEphemeralStore fallbackStore = (FallbackEphemeralStore) store;
assertTrue(fallbackStore.getPrimaryStore() instanceof InMemoryEphemeralStore);
assertTrue(fallbackStore.getSecondaryStore() instanceof LdapEphemeralStore);
migration.endMigration();
EphemeralStore.setFactory(InMemoryEphemeralStore.Factory.class);
//when migration is finished, fallback won't be enabled anymore
factory = EphemeralStore.getFactory();
store = factory.getStore();
assertTrue(store instanceof InMemoryEphemeralStore);
}
Aggregations