import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
+
import java.io.File;
import java.io.FileOutputStream;
import java.util.ArrayList;
List<ShardSnapshot> shardSnapshots = new ArrayList<>();
shardSnapshots.add(new ShardSnapshot("cars", new byte[]{1,2}));
shardSnapshots.add(new ShardSnapshot("people", new byte[]{3,4}));
- DatastoreSnapshot configSnapshot = new DatastoreSnapshot("config", null, shardSnapshots );
+ final DatastoreSnapshot configSnapshot = new DatastoreSnapshot("config", null, shardSnapshots );
shardSnapshots = new ArrayList<>();
shardSnapshots.add(new ShardSnapshot("cars", new byte[]{5,6}));
snapshotList.add(configSnapshot);
snapshotList.add(operSnapshot);
- File backupFile = new File(restoreDirectoryFile, "backup");
- try(FileOutputStream fos = new FileOutputStream(backupFile)) {
+ try (FileOutputStream fos = new FileOutputStream(backupFile)) {
SerializationUtils.serialize(snapshotList, fos);
}
- DatastoreSnapshotRestore.createInstance(restoreDirectoryPath);
+ DatastoreSnapshotRestore instance = DatastoreSnapshotRestore.instance(restoreDirectoryPath);
- verifySnapshot(configSnapshot, DatastoreSnapshotRestore.instance().getAndRemove("config"));
- verifySnapshot(operSnapshot, DatastoreSnapshotRestore.instance().getAndRemove("oper"));
+ verifySnapshot(configSnapshot, instance.getAndRemove("config"));
+ verifySnapshot(operSnapshot, instance.getAndRemove("oper"));
- assertNull("DatastoreSnapshot was not removed", DatastoreSnapshotRestore.instance().getAndRemove("config"));
+ assertNull("DatastoreSnapshot was not removed", instance.getAndRemove("config"));
assertFalse(backupFile + " was not deleted", backupFile.exists());
- DatastoreSnapshotRestore.removeInstance();
- DatastoreSnapshotRestore.createInstance("target/does-not-exist");
- assertNull("Expected null DatastoreSnapshot", DatastoreSnapshotRestore.instance().getAndRemove("config"));
- assertNull("Expected null DatastoreSnapshot", DatastoreSnapshotRestore.instance().getAndRemove("oper"));
+ instance = DatastoreSnapshotRestore.instance(restoreDirectoryPath);
+ assertNull("Expected null DatastoreSnapshot", instance.getAndRemove("config"));
+ assertNull("Expected null DatastoreSnapshot", instance.getAndRemove("oper"));
}
private static void verifySnapshot(DatastoreSnapshot expected, DatastoreSnapshot actual) {
assertTrue("ShardManager snapshots don't match", Objects.deepEquals(expected.getShardManagerSnapshot(),
actual.getShardManagerSnapshot()));
assertEquals("ShardSnapshots size", expected.getShardSnapshots().size(), actual.getShardSnapshots().size());
- for(int i = 0; i < expected.getShardSnapshots().size(); i++) {
+ for (int i = 0; i < expected.getShardSnapshots().size(); i++) {
assertEquals("ShardSnapshot " + (i + 1) + " name", expected.getShardSnapshots().get(i).getName(),
actual.getShardSnapshots().get(i).getName());
- assertArrayEquals("ShardSnapshot " + (i + 1) + " snapshot", expected.getShardSnapshots().get(i).getSnapshot(),
- actual.getShardSnapshots().get(i).getSnapshot());
+ assertArrayEquals("ShardSnapshot " + (i + 1) + " snapshot",
+ expected.getShardSnapshots().get(i).getSnapshot(), actual.getShardSnapshots().get(i).getSnapshot());
}
}
}