Search in sources :

Example 1 with EnvironmentSpecificProperties

use of org.jumpmind.properties.EnvironmentSpecificProperties in project symmetric-ds by JumpMind.

the class AbstractIntegrationTest method getWebServer.

protected SymmetricWebServer getWebServer() {
    try {
        if (server == null) {
            EnvironmentSpecificProperties properties = new EnvironmentSpecificProperties(new URL[] { TestSetupUtil.getResource(DbTestUtils.DB_TEST_PROPERTIES), TestSetupUtil.getResource("/symmetric-test.properties") }, "test.root", new String[] { "root" });
            properties.setProperty(ParameterConstants.AUTO_CONFIGURE_REG_SVR_SQL_SCRIPT, "/test-integration-root-setup.sql");
            serverDatabase = properties.getProperty("test.root");
            File rootDir = new File("target/root");
            FileUtils.deleteDirectory(rootDir);
            rootDir.mkdirs();
            File rootdbs = new File("target/rootdbs");
            FileUtils.deleteDirectory(rootdbs);
            rootdbs.mkdirs();
            File clientdbs = new File("target/clientdbs");
            FileUtils.deleteDirectory(clientdbs);
            clientdbs.mkdirs();
            File engineDir = new File(rootDir, "engines");
            engineDir.mkdirs();
            File rootPropertiesFile = new File(engineDir, "root.properties");
            FileOutputStream fos = new FileOutputStream(rootPropertiesFile);
            properties.store(fos, "unit tests");
            fos.close();
            ISymmetricEngine engine = TestSetupUtil.prepareRoot();
            engine.destroy();
            System.setProperty(SystemConstants.SYSPROP_ENGINES_DIR, engineDir.getAbsolutePath());
            System.setProperty(SystemConstants.SYSPROP_WEB_DIR, "src/main/deploy/web");
            SymmetricWebServer server = new SymmetricWebServer();
            server.setJmxEnabled(false);
            server.setJoin(false);
            server.start(Integer.parseInt(AppUtils.getPortNumber()));
            server.waitForEnginesToComeOnline(240000);
            serverTestService = new TestTablesService(server.getEngine());
            AbstractIntegrationTest.server = server;
        }
    } catch (Exception e) {
        logger.error("", e);
        fail(e.getMessage());
    }
    return server != null ? server : null;
}
Also used : EnvironmentSpecificProperties(org.jumpmind.properties.EnvironmentSpecificProperties) FileOutputStream(java.io.FileOutputStream) ISymmetricEngine(org.jumpmind.symmetric.ISymmetricEngine) File(java.io.File) InterruptedException(org.jumpmind.exception.InterruptedException) SymmetricWebServer(org.jumpmind.symmetric.SymmetricWebServer)

Example 2 with EnvironmentSpecificProperties

use of org.jumpmind.properties.EnvironmentSpecificProperties in project symmetric-ds by JumpMind.

the class EnvironmentSpecificPropertiesTest method testEnvironmentSpecificProperties.

@Test
public void testEnvironmentSpecificProperties() throws Exception {
    EnvironmentSpecificProperties properties = new EnvironmentSpecificProperties(getClass().getResource("/test.env.specifc.properties"), "environment");
    assertEquals(4, properties.size() - System.getProperties().size());
    assertEquals("one", properties.get("name1"));
    assertEquals("two", properties.get("name2"));
}
Also used : EnvironmentSpecificProperties(org.jumpmind.properties.EnvironmentSpecificProperties) Test(org.junit.Test)

Example 3 with EnvironmentSpecificProperties

use of org.jumpmind.properties.EnvironmentSpecificProperties in project symmetric-ds by JumpMind.

the class AbstractTest method getWebServer.

protected SymmetricWebServer getWebServer(String name) {
    try {
        if (!webServers.containsKey(name)) {
            EnvironmentSpecificProperties properties = new EnvironmentSpecificProperties(new URL[] { getResource(DbTestUtils.DB_TEST_PROPERTIES) }, "test." + name, new String[] { name });
            properties.putAll(getProperties(name));
            File rootDir = new File("target/" + name);
            FileUtils.deleteDirectory(rootDir);
            rootDir.mkdirs();
            File engineDir = new File(rootDir, "engines");
            engineDir.mkdirs();
            File rootPropertiesFile = new File(engineDir, "root.properties");
            FileOutputStream fos = new FileOutputStream(rootPropertiesFile);
            properties.store(fos, "unit tests");
            fos.close();
            System.setProperty(SystemConstants.SYSPROP_WAIT_FOR_DATABASE, "false");
            System.setProperty(SystemConstants.SYSPROP_ENGINES_DIR, engineDir.getAbsolutePath());
            System.setProperty(SystemConstants.SYSPROP_WEB_DIR, "src/main/deploy/web");
            ISymmetricEngine engine = null;
            int tries = 2;
            do {
                /**
                 * Firebird is flaky.  Trying to work around it.
                 */
                try {
                    engine = new ClientSymmetricEngine(properties);
                } catch (Exception ex) {
                    log.warn("Failed to create engine on the first try.  Trying again.  The root cause of the first failure was: ", ex);
                    tries--;
                    AppUtils.sleep(30000);
                }
            } while (tries > 0 && engine == null);
            IDatabasePlatform platform = engine.getDatabasePlatform();
            engine.getStagingManager().clean(0);
            engine.uninstall();
            Database database = platform.getDdlReader().readTables(platform.getDefaultCatalog(), platform.getDefaultSchema(), new String[] { "TABLE" });
            platform.dropDatabase(database, true);
            Table[] tables = getTables(name);
            if (tables != null) {
                platform.alterCaseToMatchDatabaseDefaultCase(tables);
                platform.createTables(false, true, tables);
            }
            engine.destroy();
            SymmetricWebServer server = new SymmetricWebServer();
            server.setJmxEnabled(false);
            server.setHttpPort(port);
            log.info("Starting " + name + " on port " + port);
            server.setJoin(false);
            server.start();
            server.waitForEnginesToComeOnline(240000);
            webServers.put(name, server);
            port += 200;
        }
        return webServers.get(name);
    } catch (IOException e) {
        throw new IoException(e);
    } catch (RuntimeException e) {
        throw e;
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
Also used : IDatabasePlatform(org.jumpmind.db.platform.IDatabasePlatform) Table(org.jumpmind.db.model.Table) EnvironmentSpecificProperties(org.jumpmind.properties.EnvironmentSpecificProperties) ISymmetricEngine(org.jumpmind.symmetric.ISymmetricEngine) IOException(java.io.IOException) IoException(org.jumpmind.exception.IoException) InterruptedException(org.jumpmind.exception.InterruptedException) IOException(java.io.IOException) SymmetricWebServer(org.jumpmind.symmetric.SymmetricWebServer) FileOutputStream(java.io.FileOutputStream) ClientSymmetricEngine(org.jumpmind.symmetric.ClientSymmetricEngine) Database(org.jumpmind.db.model.Database) IoException(org.jumpmind.exception.IoException) File(java.io.File)

Example 4 with EnvironmentSpecificProperties

use of org.jumpmind.properties.EnvironmentSpecificProperties in project symmetric-ds by JumpMind.

the class DbTestUtils method createDatabasePlatform.

public static IDatabasePlatform createDatabasePlatform(String name) throws Exception {
    File f = new File(String.format("target/%sdbs", name));
    FileUtils.deleteDirectory(f);
    f.mkdir();
    EnvironmentSpecificProperties properties = getEnvironmentSpecificProperties(name);
    return JdbcDatabasePlatformFactory.createNewPlatformInstance(BasicDataSourceFactory.create(properties, SecurityServiceFactory.create()), new SqlTemplateSettings(), true);
}
Also used : SqlTemplateSettings(org.jumpmind.db.sql.SqlTemplateSettings) EnvironmentSpecificProperties(org.jumpmind.properties.EnvironmentSpecificProperties) File(java.io.File)

Example 5 with EnvironmentSpecificProperties

use of org.jumpmind.properties.EnvironmentSpecificProperties in project symmetric-ds by JumpMind.

the class AbstractIntegrationTest method getClient.

protected ISymmetricEngine getClient() {
    if (client == null) {
        EnvironmentSpecificProperties properties = new EnvironmentSpecificProperties(new URL[] { TestSetupUtil.getResource(DbTestUtils.DB_TEST_PROPERTIES), TestSetupUtil.getResource("/symmetric-test.properties") }, "test.client", new String[] { "client" });
        clientDatabase = properties.getProperty("test.client");
        client = new ClientSymmetricEngine(properties);
        client.getStagingManager().clean(0);
        clientTestService = new TestTablesService(client);
        TestSetupUtil.dropAndCreateDatabaseTables(properties.getProperty("test.client"), client);
    }
    return client;
}
Also used : EnvironmentSpecificProperties(org.jumpmind.properties.EnvironmentSpecificProperties) ClientSymmetricEngine(org.jumpmind.symmetric.ClientSymmetricEngine)

Aggregations

EnvironmentSpecificProperties (org.jumpmind.properties.EnvironmentSpecificProperties)6 File (java.io.File)3 ClientSymmetricEngine (org.jumpmind.symmetric.ClientSymmetricEngine)3 ISymmetricEngine (org.jumpmind.symmetric.ISymmetricEngine)3 FileOutputStream (java.io.FileOutputStream)2 InterruptedException (org.jumpmind.exception.InterruptedException)2 SymmetricWebServer (org.jumpmind.symmetric.SymmetricWebServer)2 IOException (java.io.IOException)1 Database (org.jumpmind.db.model.Database)1 Table (org.jumpmind.db.model.Table)1 IDatabasePlatform (org.jumpmind.db.platform.IDatabasePlatform)1 SqlTemplateSettings (org.jumpmind.db.sql.SqlTemplateSettings)1 IoException (org.jumpmind.exception.IoException)1 Test (org.junit.Test)1