Search in sources :

Example 1 with OAutomaticBackup

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);
}
Also used : OAutomaticBackup(com.orientechnologies.orient.server.handler.OAutomaticBackup) CountDownLatch(java.util.concurrent.CountDownLatch) Date(java.util.Date) FileInputStream(java.io.FileInputStream) GZIPInputStream(java.util.zip.GZIPInputStream) ODatabaseImport(com.orientechnologies.orient.core.db.tool.ODatabaseImport) OServerParameterConfiguration(com.orientechnologies.orient.server.config.OServerParameterConfiguration) SimpleDateFormat(java.text.SimpleDateFormat) File(java.io.File) OCommandOutputListener(com.orientechnologies.orient.core.command.OCommandOutputListener) ODocument(com.orientechnologies.orient.core.record.impl.ODocument)

Example 2 with OAutomaticBackup

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);
}
Also used : OAutomaticBackup(com.orientechnologies.orient.server.handler.OAutomaticBackup) CountDownLatch(java.util.concurrent.CountDownLatch) Date(java.util.Date) FileInputStream(java.io.FileInputStream) OServerParameterConfiguration(com.orientechnologies.orient.server.config.OServerParameterConfiguration) SimpleDateFormat(java.text.SimpleDateFormat) File(java.io.File) ODocument(com.orientechnologies.orient.core.record.impl.ODocument)

Aggregations

ODocument (com.orientechnologies.orient.core.record.impl.ODocument)2 OServerParameterConfiguration (com.orientechnologies.orient.server.config.OServerParameterConfiguration)2 OAutomaticBackup (com.orientechnologies.orient.server.handler.OAutomaticBackup)2 File (java.io.File)2 FileInputStream (java.io.FileInputStream)2 SimpleDateFormat (java.text.SimpleDateFormat)2 Date (java.util.Date)2 CountDownLatch (java.util.concurrent.CountDownLatch)2 OCommandOutputListener (com.orientechnologies.orient.core.command.OCommandOutputListener)1 ODatabaseImport (com.orientechnologies.orient.core.db.tool.ODatabaseImport)1 GZIPInputStream (java.util.zip.GZIPInputStream)1