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

The following examples show how to use org.apache.derby.drda.NetworkServerControl#ping() . 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: DerbyBase.java    From MyBox with Apache License 2.0 6 votes vote down vote up
public static boolean isServerStarted(NetworkServerControl server) {
        boolean started = false;
        int count = 10, wait = 300;
        while (!started && (count > 0)) {
            try {
                count--;
                server.ping();
                started = true;
            } catch (Exception e) {
//                failed(e);
//                logger.debug(e.toString());
                try {
                    Thread.currentThread().sleep(wait);
                } catch (Exception ex) {
                }
            }
        }
        return started;
    }
 
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: 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 4
Source File: 919148_ReplicationRun_0_t.java    From coming with MIT License 6 votes vote down vote up
private	void ping( NetworkServerControl controller, int iterations )
throws Exception
{
    Exception	finalException = null;
    
    for ( int i = 0; i < iterations; i++ )
    {
        try
        {
            controller.ping();
            util.DEBUG("Server came up in less than "+i+" * "+PINGSERVER_SLEEP_TIME_MILLIS+"ms.");
            return;
        }
        catch (Exception e)
        { finalException = e; }
        
        Thread.sleep( PINGSERVER_SLEEP_TIME_MILLIS  );
    }
    
    String msg = "Could not ping in " 
            + iterations + " * " + PINGSERVER_SLEEP_TIME_MILLIS + "ms.: "
            + finalException.getMessage();
    util.DEBUG( msg );
   throw finalException;
    
}
 
Example 5
Source File: 919148_ReplicationRun_0_t.java    From gumtree-spoon-ast-diff with Apache License 2.0 6 votes vote down vote up
private	void ping( NetworkServerControl controller, int iterations )
throws Exception
{
    Exception	finalException = null;
    
    for ( int i = 0; i < iterations; i++ )
    {
        try
        {
            controller.ping();
            util.DEBUG("Server came up in less than "+i+" * "+PINGSERVER_SLEEP_TIME_MILLIS+"ms.");
            return;
        }
        catch (Exception e)
        { finalException = e; }
        
        Thread.sleep( PINGSERVER_SLEEP_TIME_MILLIS  );
    }
    
    String msg = "Could not ping in " 
            + iterations + " * " + PINGSERVER_SLEEP_TIME_MILLIS + "ms.: "
            + finalException.getMessage();
    util.DEBUG( msg );
   throw finalException;
    
}
 
Example 6
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 7
Source File: ClientServerDUnit.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
public static void waitForDerbyInitialization(NetworkServerControl server)
    throws InterruptedException {
  for (int tries = 1; tries <= 20; tries++) {
    try {
      server.ping();
      break;
    } catch (Throwable t) {
      Thread.sleep(1000);
    }
  }
}
 
Example 8
Source File: ClientServerDUnit.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
public static void waitForDerbyInitialization(NetworkServerControl server)
    throws InterruptedException {
  for (int tries = 1; tries <= 20; tries++) {
    try {
      server.ping();
      break;
    } catch (Throwable t) {
      Thread.sleep(1000);
    }
  }
}
 
Example 9
Source File: 919148_ReplicationRun_0_s.java    From coming with MIT License 5 votes vote down vote up
private	void ping( NetworkServerControl controller, int iterations )
throws Exception
{
    Exception	finalException = null;
    
    for ( int i = 0; i < iterations; i++ )
    {
        try
        {
            controller.ping();
            util.DEBUG("Server came up in less than "+i+" * "+PINGSERVER_SLEEP_TIME_MILLIS+"ms.");
            return;
        }
        catch (Exception e)
        { finalException = e; }
        
        Thread.sleep( PINGSERVER_SLEEP_TIME_MILLIS  );
    }
    
    String msg = "Could not ping in " 
            + iterations + " * " + PINGSERVER_SLEEP_TIME_MILLIS + "ms.: "
            + finalException.getMessage();
    util.DEBUG( msg );
   finalException.printStackTrace(); // REMOVE?
   throw new Exception(msg);
    
}
 
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	void ping( NetworkServerControl controller, int iterations )
throws Exception
{
    Exception	finalException = null;
    
    for ( int i = 0; i < iterations; i++ )
    {
        try
        {
            controller.ping();
            util.DEBUG("Server came up in less than "+i+" * "+PINGSERVER_SLEEP_TIME_MILLIS+"ms.");
            return;
        }
        catch (Exception e)
        { finalException = e; }
        
        Thread.sleep( PINGSERVER_SLEEP_TIME_MILLIS  );
    }
    
    String msg = "Could not ping in " 
            + iterations + " * " + PINGSERVER_SLEEP_TIME_MILLIS + "ms.: "
            + finalException.getMessage();
    util.DEBUG( msg );
   finalException.printStackTrace(); // REMOVE?
   throw new Exception(msg);
    
}
 
Example 11
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 12
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);
}