Java Code Examples for org.apache.derby.drda.NetworkServerControl#start()

The following examples show how to use org.apache.derby.drda.NetworkServerControl#start() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DBSynchronizerTestBase.java    From gemfirexd-oss with Apache License 2.0 6 votes vote down vote up
public static NetworkServerControl startNetworkServer(final int netPort)
    throws Exception {
  getLogWriter().info(
      "Starting a Derby Network Server on "
          + InetAddress.getLocalHost().getHostName() + ":" + netPort);
  NetworkServerControl server = new NetworkServerControl(
      InetAddress.getLocalHost(), netPort);
  // send the output to derby logs
  server.start(SanityManager.GET_DEBUG_STREAM());
  // wait for n/w server to initialize completely
  while (true) {
    Thread.sleep(500);
    try {
      server.ping();
      break;
    }
    catch (Exception e) {
    }
  }
  server.logConnections(true);
  return server;
}
 
Example 2
Source File: DBSynchronizerTestBase.java    From gemfirexd-oss with Apache License 2.0 6 votes vote down vote up
public static NetworkServerControl startNetworkServer(final int netPort)
    throws Exception {
  getLogWriter().info(
      "Starting a Derby Network Server on "
          + InetAddress.getLocalHost().getHostName() + ":" + netPort);
  NetworkServerControl server = new NetworkServerControl(
      InetAddress.getLocalHost(), netPort);
  // send the output to derby logs
  server.start(SanityManager.GET_DEBUG_STREAM());
  // wait for n/w server to initialize completely
  while (true) {
    Thread.sleep(500);
    try {
      server.ping();
      break;
    }
    catch (Exception e) {
    }
  }
  server.logConnections(true);
  return server;
}
 
Example 3
Source File: JdbcDatasetRuntimeTest.java    From components with Apache License 2.0 6 votes vote down vote up
@BeforeClass
public static void startDatabase() throws Exception {
    ServerSocket socket = new ServerSocket(0);
    port = socket.getLocalPort();
    socket.close();

    JDBC_URL = "jdbc:derby://localhost:" + port + "/target/tcomp";

    System.setProperty("derby.stream.error.file", "target/derby.log");

    derbyServer = new NetworkServerControl(InetAddress.getByName("localhost"), port);
    derbyServer.start(null);

    dataSource = new ClientDataSource();
    dataSource.setCreateDatabase("create");
    dataSource.setDatabaseName("target/tcomp");
    dataSource.setServerName("localhost");
    dataSource.setPortNumber(port);

    try (Connection connection = dataSource.getConnection()) {
        try (Statement statement = connection.createStatement()) {
            statement.executeUpdate("create table " + TABLE_IN + "(id INT, name VARCHAR(500))");
            statement.executeUpdate("create table " + TABLE_OUT + "(id INT, name VARCHAR(500))");
        }
    }
}
 
Example 4
Source File: DerbyBase.java    From MyBox with Apache License 2.0 5 votes vote down vote up
public static boolean startDerbyServer() {
        try {
            boolean portUsed = NetworkTools.isPortUsed(port);
            int uPort = port;
            if (portUsed) {
                if (DerbyBase.isServerStarted(port)) {
                    logger.debug("Derby server is already started in port " + port + ".");
                    return true;
                } else {
                    uPort = NetworkTools.findFreePort(port);
                }
            }
            NetworkServerControl server = new NetworkServerControl(InetAddress.getByName(host),
                    uPort, CommonValues.AppDerbyUser, CommonValues.AppDerbyPassword);
            status = DerbyStatus.Starting;
            server.start(null);
//            server.setTraceDirectory("d:/tmp");
            server.trace(false);
            if (isServerStarted(server)) {
                port = uPort;
                logger.debug("Derby server is listening in port " + port + ".");
                status = DerbyStatus.Nerwork;
                return true;
            } else {
                status = DerbyStatus.NerworkFailed;
                return false;
            }
        } catch (Exception e) {
            logger.debug(e.toString());
            status = DerbyStatus.NerworkFailed;
            return false;
        }
    }
 
Example 5
Source File: DerbyDatabaseTestResource.java    From quarkus with Apache License 2.0 5 votes vote down vote up
@Override
public Map<String, String> start() {
    try {
        NetworkServerControl server = new NetworkServerControl();
        server.start(new PrintWriter(System.out));
        for (int i = 1; i <= NUMBER_OF_PINGS; i++) {
            try {
                System.out.println("[INFO] Attempt " + i + " to see if Derby Network server started");
                server.ping();
                break;
            } catch (Exception ex) {
                if (i == NUMBER_OF_PINGS) {
                    System.out.println("Derby Network server failed to start");
                    ex.printStackTrace();
                    throw ex;
                }
                try {
                    Thread.sleep(SLEEP_BETWEEN_PINGS);
                } catch (InterruptedException ignore) {
                }
            }
        }
        System.out.println("[INFO] Derby database started in TCP server mode");
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
    return Collections.emptyMap();
}
 
Example 6
Source File: 919148_ReplicationRun_0_s.java    From coming with MIT License 5 votes vote down vote up
private NetworkServerControl startServer_direct(String serverHost, 
        String interfacesToListenOn, 
        int serverPort, 
        String fullDbDirPath,
        String securityOption) // FIXME? true/false?
throws Exception
{ // Wotk in progress. Not currently used! Only partly tested!
    util.DEBUG("startServer_direct " + serverHost 
            + " " + interfacesToListenOn +  " " + serverPort
            + " " + fullDbDirPath);
    assertTrue("Attempt to start server on non-localhost: " + serverHost, 
            serverHost.equalsIgnoreCase("localhost"));
    
    System.setProperty("derby.system.home", fullDbDirPath);
    System.setProperty("user.dir", fullDbDirPath);
    
    NetworkServerControl server = new NetworkServerControl(
            InetAddress.getByName(interfacesToListenOn), serverPort);
    
    server.start(null); 
    pingServer(serverHost, serverPort, 150);
    
    Properties sp = server.getCurrentProperties();
    sp.setProperty("noSecurityManager", 
            securityOption.equalsIgnoreCase("-noSecurityManager")?"true":"false");
    // derby.log for both master and slave ends up in masters system!
    // Both are run in the same VM! Not a good idea?
    return server;
}
 
Example 7
Source File: 919148_ReplicationRun_0_t.java    From coming with MIT License 5 votes vote down vote up
private NetworkServerControl startServer_direct(String serverHost, 
        String interfacesToListenOn, 
        int serverPort, 
        String fullDbDirPath,
        String securityOption) // FIXME? true/false?
throws Exception
{ // Wotk in progress. Not currently used! Only partly tested!
    util.DEBUG("startServer_direct " + serverHost 
            + " " + interfacesToListenOn +  " " + serverPort
            + " " + fullDbDirPath);
    assertTrue("Attempt to start server on non-localhost: " + serverHost, 
            serverHost.equalsIgnoreCase("localhost"));
    
    System.setProperty("derby.system.home", fullDbDirPath);
    System.setProperty("user.dir", fullDbDirPath);
    
    NetworkServerControl server = new NetworkServerControl(
            InetAddress.getByName(interfacesToListenOn), serverPort);
    
    server.start(null); 
    pingServer(serverHost, serverPort, 150);
    
    Properties sp = server.getCurrentProperties();
    sp.setProperty("noSecurityManager", 
            securityOption.equalsIgnoreCase("-noSecurityManager")?"true":"false");
    // derby.log for both master and slave ends up in masters system!
    // Both are run in the same VM! Not a good idea?
    return server;
}
 
Example 8
Source File: JDBCBeamRuntimeTest.java    From components with Apache License 2.0 5 votes vote down vote up
@BeforeClass
public static void startDatabase() throws Exception {
    ServerSocket socket = new ServerSocket(0);
    port = socket.getLocalPort();
    socket.close();

    LOGGER.info("Starting Derby database on {}", port);

    JDBC_URL = "jdbc:derby://localhost:" + port + "/target/tcomp";

    System.setProperty("derby.stream.error.file", "target/derby.log");

    derbyServer = new NetworkServerControl(InetAddress.getByName("localhost"), port);
    derbyServer.start(null);

    dataSource = new ClientDataSource();
    dataSource.setCreateDatabase("create");
    dataSource.setDatabaseName("target/tcomp");
    dataSource.setServerName("localhost");
    dataSource.setPortNumber(port);

    try (Connection connection = dataSource.getConnection()) {
        try (Statement statement = connection.createStatement()) {
            statement.executeUpdate("create table " + TABLE_IN + "(id INT, name VARCHAR(500))");
            statement.executeUpdate("create table " + TABLE_OUT + "(id INT, name VARCHAR(500))");
        }
    }
}
 
Example 9
Source File: ServerDatabase.java    From nordpos with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void start() throws Exception {
    server = new NetworkServerControl(InetAddress.getByName("localhost"), 1527);
    System.setProperty("derby.system.home", new File(new File(System.getProperty("user.home")), ".derby-db").getAbsolutePath());
    java.io.PrintWriter consoleWriter = new java.io.PrintWriter(System.out, true);
    server.start(consoleWriter);
}
 
Example 10
Source File: 919148_ReplicationRun_0_s.java    From gumtree-spoon-ast-diff with Apache License 2.0 5 votes vote down vote up
private NetworkServerControl startServer_direct(String serverHost, 
        String interfacesToListenOn, 
        int serverPort, 
        String fullDbDirPath,
        String securityOption) // FIXME? true/false?
throws Exception
{ // Wotk in progress. Not currently used! Only partly tested!
    util.DEBUG("startServer_direct " + serverHost 
            + " " + interfacesToListenOn +  " " + serverPort
            + " " + fullDbDirPath);
    assertTrue("Attempt to start server on non-localhost: " + serverHost, 
            serverHost.equalsIgnoreCase("localhost"));
    
    System.setProperty("derby.system.home", fullDbDirPath);
    System.setProperty("user.dir", fullDbDirPath);
    
    NetworkServerControl server = new NetworkServerControl(
            InetAddress.getByName(interfacesToListenOn), serverPort);
    
    server.start(null); 
    pingServer(serverHost, serverPort, 150);
    
    Properties sp = server.getCurrentProperties();
    sp.setProperty("noSecurityManager", 
            securityOption.equalsIgnoreCase("-noSecurityManager")?"true":"false");
    // derby.log for both master and slave ends up in masters system!
    // Both are run in the same VM! Not a good idea?
    return server;
}
 
Example 11
Source File: 919148_ReplicationRun_0_t.java    From gumtree-spoon-ast-diff with Apache License 2.0 5 votes vote down vote up
private NetworkServerControl startServer_direct(String serverHost, 
        String interfacesToListenOn, 
        int serverPort, 
        String fullDbDirPath,
        String securityOption) // FIXME? true/false?
throws Exception
{ // Wotk in progress. Not currently used! Only partly tested!
    util.DEBUG("startServer_direct " + serverHost 
            + " " + interfacesToListenOn +  " " + serverPort
            + " " + fullDbDirPath);
    assertTrue("Attempt to start server on non-localhost: " + serverHost, 
            serverHost.equalsIgnoreCase("localhost"));
    
    System.setProperty("derby.system.home", fullDbDirPath);
    System.setProperty("user.dir", fullDbDirPath);
    
    NetworkServerControl server = new NetworkServerControl(
            InetAddress.getByName(interfacesToListenOn), serverPort);
    
    server.start(null); 
    pingServer(serverHost, serverPort, 150);
    
    Properties sp = server.getCurrentProperties();
    sp.setProperty("noSecurityManager", 
            securityOption.equalsIgnoreCase("-noSecurityManager")?"true":"false");
    // derby.log for both master and slave ends up in masters system!
    // Both are run in the same VM! Not a good idea?
    return server;
}
 
Example 12
Source File: DynamicJdbcIOTest.java    From DataflowTemplates with Apache License 2.0 4 votes vote down vote up
@BeforeClass
public static void startDatabase() throws Exception {
  ServerSocket socket = new ServerSocket(0);
  port = socket.getLocalPort();
  socket.close();

  LOG.info("Starting Derby database on {}", port);

  // by default, derby uses a lock timeout of 60 seconds. In order to speed up the test
  // and detect the lock faster, we decrease this timeout
  System.setProperty("derby.locks.waitTimeout", "2");
  System.setProperty("derby.stream.error.file", "target/derby.log");

  derbyServer = new NetworkServerControl(InetAddress.getByName("localhost"), port);
  StringWriter out = new StringWriter();
  derbyServer.start(new PrintWriter(out));
  boolean started = false;
  int count = 0;
  // Use two different methods to detect when server is started:
  // 1) Check the server stdout for the "started" string
  // 2) wait up to 15 seconds for the derby server to start based on a ping
  // on faster machines and networks, this may return very quick, but on slower
  // networks where the DNS lookups are slow, this may take a little time
  while (!started && count < 30) {
    if (out.toString().contains("started")) {
      started = true;
    } else {
      count++;
      TimeUnit.MILLISECONDS.sleep(500);
      try {
        derbyServer.ping();
        started = true;
      } catch (Throwable t) {
        // ignore, still trying to start
      }
    }
  }

  if (!started) {
    // Server has not started in the expected time frame
    throw new IllegalStateException("Derby server failed to start.");
  }

  dataSource = new ClientDataSource();
  dataSource.setCreateDatabase("create");
  dataSource.setDatabaseName("target/beam");
  dataSource.setServerName("localhost");
  dataSource.setPortNumber(port);

  readTableName = getTestTableName("UT_READ");

  createTable(dataSource, readTableName);
  addInitialData(dataSource, readTableName);
}
 
Example 13
Source File: JdbcIOTest.java    From beam with Apache License 2.0 4 votes vote down vote up
@BeforeClass
public static void beforeClass() throws Exception {
  port = NetworkTestHelper.getAvailableLocalPort();
  LOG.info("Starting Derby database on {}", port);

  // by default, derby uses a lock timeout of 60 seconds. In order to speed up the test
  // and detect the lock faster, we decrease this timeout
  System.setProperty("derby.locks.waitTimeout", "2");
  System.setProperty("derby.stream.error.file", "target/derby.log");

  derbyServer = new NetworkServerControl(InetAddress.getByName("localhost"), port);
  StringWriter out = new StringWriter();
  derbyServer.start(new PrintWriter(out));
  boolean started = false;
  int count = 0;
  // Use two different methods to detect when server is started:
  // 1) Check the server stdout for the "started" string
  // 2) wait up to 15 seconds for the derby server to start based on a ping
  // on faster machines and networks, this may return very quick, but on slower
  // networks where the DNS lookups are slow, this may take a little time
  while (!started && count < 30) {
    if (out.toString().contains("started")) {
      started = true;
    } else {
      count++;
      Thread.sleep(500);
      try {
        derbyServer.ping();
        started = true;
      } catch (Throwable t) {
        // ignore, still trying to start
      }
    }
  }

  dataSource = new ClientDataSource();
  dataSource.setCreateDatabase("create");
  dataSource.setDatabaseName("target/beam");
  dataSource.setServerName("localhost");
  dataSource.setPortNumber(port);

  readTableName = DatabaseTestHelper.getTestTableName("UT_READ");

  DatabaseTestHelper.createTable(dataSource, readTableName);
  addInitialData(dataSource, readTableName);
}