use of com.orientechnologies.orient.server.handler.OAutomaticBackup in project orientdb by orientechnologies.
the class LuceneAutomaticBackupRestoreTest method shouldExportImport.
@Test
public void shouldExportImport() throws IOException, InterruptedException {
List<?> query = databaseDocumentTx.query(new OSQLSynchQuery<Object>("select from City where name lucene 'Rome'"));
Assert.assertEquals(query.size(), 1);
String jsonConfig = OIOUtils.readStreamAsString(getClass().getClassLoader().getResourceAsStream("automatic-backup.json"));
ODocument doc = new ODocument().fromJSON(jsonConfig);
doc.field("enabled", true);
doc.field("targetFileName", "${DBNAME}.json");
doc.field("targetDirectory", BACKUPDIR);
doc.field("mode", "EXPORT");
doc.field("dbInclude", new String[] { "LuceneAutomaticBackupRestoreTest" });
doc.field("firstTime", new SimpleDateFormat("HH:mm:ss").format(new Date(System.currentTimeMillis() + 2000)));
OIOUtils.writeFile(new File(tempFolder.getRoot().getAbsolutePath() + "/config/automatic-backup.json"), doc.toJSON());
final OAutomaticBackup aBackup = new OAutomaticBackup();
final OServerParameterConfiguration[] config = new OServerParameterConfiguration[] {};
aBackup.config(server, config);
final CountDownLatch latch = new CountDownLatch(1);
aBackup.registerListener(new OAutomaticBackup.OAutomaticBackupListener() {
@Override
public void onBackupCompleted(String database) {
latch.countDown();
}
});
latch.await();
aBackup.sendShutdown();
// RESTORE
databaseDocumentTx.drop();
databaseDocumentTx.create();
GZIPInputStream stream = new GZIPInputStream(new FileInputStream(BACKUFILE + ".json.gz"));
new ODatabaseImport(databaseDocumentTx, stream, new OCommandOutputListener() {
@Override
public void onMessage(String s) {
}
}).importDatabase();
databaseDocumentTx.close();
// VERIFY
databaseDocumentTx.open("admin", "admin");
assertThat(databaseDocumentTx.countClass("City")).isEqualTo(1);
OIndex<?> index = databaseDocumentTx.getMetadata().getIndexManager().getIndex("City.name");
assertThat(index).isNotNull();
assertThat(index.getType()).isEqualTo(OClass.INDEX_TYPE.FULLTEXT.name());
assertThat(databaseDocumentTx.query(new OSQLSynchQuery<Object>("select from City where name lucene 'Rome'"))).hasSize(1);
}
use of com.orientechnologies.orient.server.handler.OAutomaticBackup in project orientdb by orientechnologies.
the class LuceneAutomaticBackupRestoreTest method shouldBackupAndRestore.
@Test
public void shouldBackupAndRestore() throws IOException, InterruptedException {
List<?> query = databaseDocumentTx.query(new OSQLSynchQuery<Object>("select from City where name lucene 'Rome'"));
Assert.assertEquals(query.size(), 1);
String jsonConfig = OIOUtils.readStreamAsString(getClass().getClassLoader().getResourceAsStream("automatic-backup.json"));
ODocument doc = new ODocument().fromJSON(jsonConfig);
doc.field("enabled", true);
doc.field("targetFileName", "${DBNAME}.zip");
doc.field("targetDirectory", BACKUPDIR);
doc.field("dbInclude", new String[] { "LuceneAutomaticBackupRestoreTest" });
doc.field("firstTime", new SimpleDateFormat("HH:mm:ss").format(new Date(System.currentTimeMillis() + 2000)));
OIOUtils.writeFile(new File(tempFolder.getRoot().getAbsolutePath() + "/config/automatic-backup.json"), doc.toJSON());
final OAutomaticBackup aBackup = new OAutomaticBackup();
final OServerParameterConfiguration[] config = new OServerParameterConfiguration[] {};
aBackup.config(server, config);
final CountDownLatch latch = new CountDownLatch(1);
aBackup.registerListener(new OAutomaticBackup.OAutomaticBackupListener() {
@Override
public void onBackupCompleted(String database) {
latch.countDown();
}
});
latch.await();
aBackup.sendShutdown();
// RESTORE
databaseDocumentTx.drop();
databaseDocumentTx.create();
FileInputStream stream = new FileInputStream(new File(BACKUFILE + ".zip"));
databaseDocumentTx.restore(stream, null, null, null);
databaseDocumentTx.close();
// VERIFY
databaseDocumentTx.open("admin", "admin");
assertThat(databaseDocumentTx.countClass("City")).isEqualTo(1);
OIndex<?> index = databaseDocumentTx.getMetadata().getIndexManager().getIndex("City.name");
assertThat(index).isNotNull();
assertThat(index.getType()).isEqualTo(OClass.INDEX_TYPE.FULLTEXT.name());
assertThat(databaseDocumentTx.query(new OSQLSynchQuery<Object>("select from City where name lucene 'Rome'"))).hasSize(1);
}
Aggregations