use of com.orientechnologies.orient.core.db.tool.ODatabaseImport in project orientdb by orientechnologies.
the class AutomaticBackupTest method testExport.
//// @Test
// //TODO: move to EE test suite
// public void testIncrementalBackup() throws IOException, ClassNotFoundException, MalformedObjectNameException,
// InstanceAlreadyExistsException, NotCompliantMBeanException, MBeanRegistrationException {
// if (new File(BACKUPDIR + "/" + DBNAME).exists())
// OFileUtils.deleteRecursively(new File(BACKUPDIR + "/" + DBNAME));
//
// final OAutomaticBackup aBackup = new OAutomaticBackup();
//
// final OServerParameterConfiguration[] config = new OServerParameterConfiguration[] {
// new OServerParameterConfiguration("firstTime",
// new SimpleDateFormat("HH:mm:ss").format(new Date(System.currentTimeMillis() + 2000))),
// new OServerParameterConfiguration("delay", "1d"), new OServerParameterConfiguration("mode", "INCREMENTAL_BACKUP"),
// new OServerParameterConfiguration("target.directory", BACKUPDIR) };
//
// aBackup.config(server, config);
//
// try {
// Thread.sleep(5000);
// } catch (InterruptedException e) {
// e.printStackTrace();
// }
//
// aBackup.sendShutdown();
//
// final ODatabaseDocumentTx database2 = new ODatabaseDocumentTx(URL2);
// if (database2.exists())
// database2.open("admin", "admin").drop();
// database2.create(BACKUPDIR + "/" + DBNAME);
//
// Assert.assertEquals(database2.countClass("TestBackup"), 1);
// }
@Test
public void testExport() throws IOException, ClassNotFoundException, MalformedObjectNameException, InstanceAlreadyExistsException, NotCompliantMBeanException, MBeanRegistrationException {
if (new File(BACKUPDIR + "/fullExport.json.gz").exists())
new File(BACKUPDIR + "/fullExport.json.gz").delete();
final OAutomaticBackup aBackup = new OAutomaticBackup();
final OServerParameterConfiguration[] config = new OServerParameterConfiguration[] { new OServerParameterConfiguration("firstTime", new SimpleDateFormat("HH:mm:ss").format(new Date(System.currentTimeMillis() + 2000))), new OServerParameterConfiguration("delay", "1d"), new OServerParameterConfiguration("mode", "EXPORT"), new OServerParameterConfiguration("target.directory", BACKUPDIR), new OServerParameterConfiguration("target.fileName", "fullExport.json.gz") };
aBackup.config(server, config);
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
e.printStackTrace();
}
aBackup.sendShutdown();
final ODatabaseDocumentTx database2 = new ODatabaseDocumentTx(URL2);
if (database2.exists())
database2.open("admin", "admin").drop();
database2.create();
new ODatabaseImport(database2, BACKUPDIR + "/fullExport.json.gz", null).importDatabase();
Assert.assertEquals(database2.countClass("TestBackup"), 1);
}
use of com.orientechnologies.orient.core.db.tool.ODatabaseImport in project orientdb by orientechnologies.
the class DbImportExportTest method testDbImport.
@Test(dependsOnMethods = "testDbExport")
public void testDbImport() throws IOException {
final File importDir = new File(testPath + "/" + NEW_DB_PATH);
if (importDir.exists())
for (File f : importDir.listFiles()) f.delete();
else
importDir.mkdir();
ODatabaseDocumentTx database = new ODatabaseDocumentTx(getStorageType() + ":" + testPath + "/" + NEW_DB_URL);
database.create();
ODatabaseImport dbImport = new ODatabaseImport(database, testPath + "/" + exportFilePath, this);
// UNREGISTER ALL THE HOOKS
for (ORecordHook hook : new ArrayList<ORecordHook>(database.getHooks().keySet())) {
database.unregisterHook(hook);
}
dbImport.setPreserveRids(true);
dbImport.setDeleteRIDMapping(false);
dbImport.importDatabase();
dbImport.close();
database.close();
}
use of com.orientechnologies.orient.core.db.tool.ODatabaseImport in project orientdb by orientechnologies.
the class ObjectExportImportTest method testExportImport.
@Test
public void testExportImport() throws IOException {
OObjectDatabaseTx db = new OObjectDatabaseTx("memory:test");
db.create();
db.setAutomaticSchemaGeneration(true);
db.getMetadata().getSchema().synchronizeSchema();
assertNotNull(db.getMetadata().getSchema().getClass("ODocumentWrapper"));
byte[] bytes;
ByteArrayOutputStream byteOutputStream = new ByteArrayOutputStream();
new ODatabaseExport(db.getUnderlying(), byteOutputStream, new OCommandOutputListener() {
@Override
public void onMessage(String iText) {
}
}).exportDatabase().close();
bytes = byteOutputStream.toByteArray();
OObjectDatabaseTx db1 = new OObjectDatabaseTx("memory:test1");
db1.create();
db1.setAutomaticSchemaGeneration(true);
db1.getMetadata().getSchema().synchronizeSchema();
InputStream input = new ByteArrayInputStream(bytes);
new ODatabaseImport(db1.getUnderlying(), input, new OCommandOutputListener() {
@Override
public void onMessage(String iText) {
}
}).importDatabase().close();
assertNotNull(db1.getMetadata().getSchema().getClass("ODocumentWrapper"));
}
Aggregations