use of com.zimbra.cs.ephemeral.migrate.AttributeMigration.EntrySource 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);
}
use of com.zimbra.cs.ephemeral.migrate.AttributeMigration.EntrySource in project zm-mailbox by Zimbra.
the class MigrateAttributesTest method testMigrateAlreadyMigratedAccount.
@Test
public void testMigrateAlreadyMigratedAccount() throws Exception {
Provisioning prov = Provisioning.getInstance();
// create a new account that will not have any data to migrate
Account acct = prov.createAccount("user2", "test123", new HashMap<String, Object>());
EntrySource source = new DummyEntrySource(acct);
Multimap<String, Object> deletedAttrs = LinkedListMultimap.create();
List<EphemeralInput> results = new LinkedList<EphemeralInput>();
List<String> attrsToMigrate = Arrays.asList(new String[] { Provisioning.A_zimbraAuthTokens, Provisioning.A_zimbraCsrfTokenData, Provisioning.A_zimbraLastLogonTimestamp });
DummyMigrationCallback callback = new DummyMigrationCallback(results);
callback.throwErrorDuringMigration = false;
AttributeMigration.setCallback(callback);
AttributeMigration migration = new AttributeMigration("testAttributeMigration", attrsToMigrate, source, null);
migration.migrateAllAccounts();
assertTrue(results.isEmpty());
}
use of com.zimbra.cs.ephemeral.migrate.AttributeMigration.EntrySource in project zm-mailbox by Zimbra.
the class MigrateAttributesTest method testMigrationInfo.
@Test
public void testMigrationInfo() throws Exception {
MigrationInfo info = MigrationInfo.getFactory().getInfo();
try {
EphemeralStore destination = EphemeralStore.getFactory().getStore();
EntrySource source = new DummyEntrySource(acct);
List<String> attrsToMigrate = new ArrayList<String>();
MigrationCallback callback = new DummyMigrationCallback(destination);
AttributeMigration.setCallback(callback);
AttributeMigration migration = new AttributeMigration("testAttributeMigration", attrsToMigrate, source, null);
assertEquals(Status.NONE, info.getStatus());
migration.beginMigration();
assertEquals(Status.IN_PROGRESS, info.getStatus());
migration.endMigration();
assertEquals(Status.COMPLETED, info.getStatus());
} finally {
info.clearData();
}
}
use of com.zimbra.cs.ephemeral.migrate.AttributeMigration.EntrySource 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);
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);
AttributeMigration.setCallback(callback);
AttributeMigration migration = new AttributeMigration("testAttributeMigration", attrsToMigrate, source, null);
MigrationInfo info = MigrationInfo.getFactory().getInfo();
// 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());
assertTrue(info.getStatus() == Status.COMPLETED);
}
use of com.zimbra.cs.ephemeral.migrate.AttributeMigration.EntrySource in project zm-mailbox by Zimbra.
the class MigrateAttributesTest method testErrorDuringMigration.
@Test
public void testErrorDuringMigration() throws Exception {
List<EphemeralInput> results = new LinkedList<EphemeralInput>();
EntrySource source = new DummyEntrySource(acct, acct, acct);
List<String> attrsToMigrate = Arrays.asList(new String[] { Provisioning.A_zimbraAuthTokens, Provisioning.A_zimbraCsrfTokenData, Provisioning.A_zimbraLastLogonTimestamp });
DummyMigrationCallback callback = new DummyMigrationCallback(results);
callback.throwErrorDuringMigration = true;
AttributeMigration.setCallback(callback);
AttributeMigration migration = new AttributeMigration("testAttributeMigration", attrsToMigrate, source, null);
MigrationInfo info = MigrationInfo.getFactory().getInfo();
info.clearData();
try {
migration.migrateAllAccounts();
fail("synchronous migration should throw an exception");
} catch (ServiceException e) {
// make sure the root exception got thrown
assertTrue(e.getMessage().contains("Failure during migration"));
}
// make sure nothing got migrated
assertEquals(0, results.size());
migration = new AttributeMigration("testAttributeMigration", attrsToMigrate, source, 3);
info.clearData();
try {
migration.migrateAllAccounts();
fail("async migration should throw an exception");
} catch (ServiceException e) {
assertTrue(e.getMessage().contains("Failure during migration"));
assertTrue(info.getStatus() == Status.FAILED);
}
assertEquals(0, results.size());
}
Aggregations