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

The following examples show how to use org.apache.derby.drda.NetworkServerControl#shutdown() . 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: SerialDBSynchronizerPart2DUnit.java    From gemfirexd-oss with Apache License 2.0 4 votes vote down vote up
public void testBug42706_3() throws Exception {

    Connection derbyConn = null;
    Statement derbyStmt = null;
    NetworkServerControl server = null;
    boolean tablesCreated = false;
    try {
      server = startNetworkServer();
      createDerbyValidationArtefacts();
      String derbyDbUrl = "jdbc:derby://"
          + InetAddress.getLocalHost().getHostName() + ':' + this.netPort
          + "/newDB;create=true;";
      if (TestUtil.currentUserName != null) {
        derbyDbUrl += ("user=" + TestUtil.currentUserName + ";password="
            + TestUtil.currentUserPassword + ';');
      }
      derbyConn = DriverManager.getConnection(derbyDbUrl);
      // create schema
      derbyStmt = derbyConn.createStatement();

      startServerVMs(2, -1, "SG1");

      // create table
      serverSQLExecute(1,
          "create table TESTTABLE (ID int not null primary key , "
              + "DESCRIPTION varchar(1024) , ADDRESS varchar(1024), ID1 int ) "
              + "AsyncEventListener (WBCL2)   ");

      tablesCreated = true;

      Runnable runnable = getExecutorForWBCLConfiguration("SG1", "WBCL2",
          "com.pivotal.gemfirexd.callbacks.DBSynchronizer",
          "org.apache.derby.jdbc.ClientDriver", derbyDbUrl, true,
          Integer.valueOf(1), null, Boolean.TRUE, null, null, null, 100000,
          "org.apache.derby.jdbc.ClientDriver," + derbyDbUrl, false);
      serverExecute(1, runnable);
      Runnable startWBCL = startAsyncEventListener("WBCL2");
      serverExecute(1, startWBCL);
      startClientVMs(1, 0, null);
      Connection conn = TestUtil.jdbcConn;
      String schema = ((EmbedConnection)TestUtil.jdbcConn)
          .getLanguageConnection().getCurrentSchemaName();
      if (schema == null) {
        schema = Misc.getDefaultSchemaName(((EmbedConnection)TestUtil.jdbcConn)
            .getLanguageConnection());
      }
      conn.createStatement();

      GfxdCallbacksTest.addLoader(schema, "TESTTABLE",
          "com.pivotal.gemfirexd.dbsync.DBSynchronizerTestBase$GfxdTestRowLoader",
          "");
      sqlExecuteVerify(new int[] { 1 }, null,
          "select ID from TESTTABLE where ID = 1", null, null);

      sqlExecuteVerify(new int[] { 1 }, null,
          "select ID from TESTTABLE where ID = 2", null, null);

      sqlExecuteVerify(new int[] { 1 }, null,
          "select ID from TESTTABLE where ID = 3", null, null);

      SerializableCallable queueChecker = getEmptyQueueChecker();
      Boolean retVal = (Boolean)serverExecute(1, queueChecker);
      assertTrue(retVal.booleanValue());

      retVal = (Boolean)serverExecute(2, queueChecker);
      assertTrue(retVal.booleanValue());

      ResultSet rs = derbyStmt.executeQuery("select * from testtable ");
      assertFalse(rs.next());

    } finally {
      ok = false;
      derbyStmt.executeUpdate("delete from testtable");
      cleanDerbyArtifacts(derbyStmt, new String[] {}, new String[] {},
          new String[] { "TESTTABLE" }, derbyConn);
      if (tablesCreated) {
        clientSQLExecute(1, "drop table TESTTABLE");
        // derbyStmt.execute("drop procedure validateTestEnd");
      }
      try {
        DriverManager.getConnection("jdbc:derby:;shutdown=true");
      } catch (SQLException sqle) {
        if (sqle.getMessage().indexOf("shutdown") == -1) {
          sqle.printStackTrace();
          throw sqle;
        }
      }
      if (server != null) {
        server.shutdown();
      }
    }
  }
 
Example 2
Source File: SerialDBSynchronizerPart2DUnit.java    From gemfirexd-oss with Apache License 2.0 4 votes vote down vote up
public void testTransactionalBehaviourOfDBSynchronizer_2() throws Exception {
  Connection derbyConn = null;
  Statement derbyStmt = null;
  NetworkServerControl server = null;
  try {
    server = startNetworkServer();
    createDerbyValidationArtefacts();
    String derbyDbUrl = "jdbc:derby://"
        + InetAddress.getLocalHost().getHostName() + ':' + this.netPort
        + "/newDB;create=true;";
    if (TestUtil.currentUserName != null) {
      derbyDbUrl += ("user=" + TestUtil.currentUserName + ";password="
          + TestUtil.currentUserPassword + ';');
    }
    derbyConn = DriverManager.getConnection(derbyDbUrl);
    // create schema
    derbyStmt = derbyConn.createStatement();
    // Create the controller VM as client which belongs to default server
    // group
    startVMs(1, 1, -1, "SG1", null);
    // create table
    clientSQLExecute(1, "create table TESTTABLE "
        + "(ID int not null primary key, DESCRIPTION varchar(1024), "
        + "ADDRESS varchar(1024), ID1 int) AsyncEventListener (WBCL1) ");

    Runnable runnable = getExecutorForWBCLConfiguration("SG1", "WBCL1",
        "com.pivotal.gemfirexd.callbacks.DBSynchronizer",
        "org.apache.derby.jdbc.ClientDriver", derbyDbUrl, true,
        Integer.valueOf(1), null, Boolean.FALSE, null, null, null, 100000,
        "org.apache.derby.jdbc.ClientDriver," + derbyDbUrl, false);
    runnable.run();
    Runnable startWBCL = startAsyncEventListener("WBCL1");
    clientExecute(1, startWBCL);
    Connection conn = TestUtil.jdbcConn;
    conn.setTransactionIsolation(Connection.TRANSACTION_READ_COMMITTED);
    conn.setAutoCommit(false);
    Statement stmt = conn.createStatement();
    PreparedStatement pstmt1 = conn
        .prepareStatement("insert into testtable values(?,?,?,?)");
    for (int i = 1; i < 10; ++i) {
      pstmt1.setInt(1, i);
      pstmt1.setString(2, "desc" + i);
      pstmt1.setString(3, "Add" + i);
      pstmt1.setInt(4, i);
      assertEquals(1, pstmt1.executeUpdate());
    }
    conn.commit();
    PreparedStatement pstmt2 = conn
        .prepareStatement("update testtable set ID1 = ? where description = ?");
    for (int i = 1; i < 5; ++i) {
      pstmt2.setInt(1, i * 10);
      pstmt2.setString(2, "desc" + i);
      assertEquals(1, pstmt2.executeUpdate());
    }
    conn.commit();
    PreparedStatement pstmt3 = conn
        .prepareStatement("select ID1 from TestTable where description = ?");
    for (int i = 1; i < 5; ++i) {
      pstmt3.setString(1, "desc" + i);
      ResultSet rs = pstmt3.executeQuery();
      assertTrue(rs.next());
      assertEquals(i * 10, rs.getInt(1));
    }
    // Now a delete a row & reinsert the row but with changed data . The
    // deletion should go via bulk op route
    assertEquals(1,
        stmt.executeUpdate("delete from TESTTABLE where ADDRESS = 'Add5'"));
    // Insert a row corresponding to the row deleted with Address as Add5
    pstmt1.setInt(1, 5);
    pstmt1.setString(2, "desc.5");
    pstmt1.setString(3, "Add5");
    pstmt1.setInt(4, 5);
    assertEquals(1, pstmt1.executeUpdate());
    conn.commit();
    // PK delete
    stmt.executeUpdate("delete from TESTTABLE where ID = " + DELETED_KEY);
    conn.commit();
    blockForValidation();
    stopAsyncEventListener("WBCL1").run();
    validateResults(derbyStmt, "select * from testtable", this.netPort, true);
  } finally {
    cleanDerbyArtifacts(derbyStmt, new String[] { "validateTestEnd" },
        new String[] { "test_ok" }, new String[] { "TESTTABLE" }, derbyConn);
    // might get ShutdownExceptions in derby connection close
    addExpectedDerbyException(ShutdownException.class.getName());
    try {
      DriverManager.getConnection("jdbc:derby:;shutdown=true");
    } catch (SQLException sqle) {
      if (sqle.getMessage().indexOf("shutdown") == -1) {
        sqle.printStackTrace();
        throw sqle;
      }
    }
    if (server != null) {
      server.shutdown();
    }
  }
}
 
Example 3
Source File: SerialDBSynchronizerPart2DUnit.java    From gemfirexd-oss with Apache License 2.0 4 votes vote down vote up
public void testTransactionalBehaviourOfAsyncEventListener_2()
    throws Exception {
  Connection derbyConn = null;
  Statement derbyStmt = null;
  NetworkServerControl server = null;
  try {
    server = startNetworkServer();
    createDerbyValidationArtefacts();
    String derbyDbUrl = "jdbc:derby://"
        + InetAddress.getLocalHost().getHostName() + ':' + this.netPort
        + "/newDB;create=true;";
    if (TestUtil.currentUserName != null) {
      derbyDbUrl += ("user=" + TestUtil.currentUserName + ";password="
          + TestUtil.currentUserPassword + ';');
    }
    derbyConn = DriverManager.getConnection(derbyDbUrl);
    // create schema
    derbyStmt = derbyConn.createStatement();
    // Create the controller VM as client which belongs to default server
    // group
    startVMs(1, 1, -1, "SG1", null);
    // create table
    clientSQLExecute(1, "create table TESTTABLE (ID int not null "
        + "primary key, DESCRIPTION varchar(1024), ADDRESS varchar(1024), "
        + "ID1 int) AsyncEventListener (WBCL1)");

    Runnable runnable = getExecutorForWBCLConfiguration("SG1", "WBCL1",
        TXAsyncEventListener.class.getName(), null, derbyDbUrl, true,
        Integer.valueOf(1), null, Boolean.FALSE, null, null, null, 100000,
        null, false);
    runnable.run();
    Runnable startWBCL = startAsyncEventListener("WBCL1");
    clientExecute(1, startWBCL);
    Connection conn = TestUtil.jdbcConn;
    conn.setTransactionIsolation(Connection.TRANSACTION_READ_COMMITTED);
    conn.setAutoCommit(false);
    Statement stmt = conn.createStatement();
    PreparedStatement pstmt1 = conn
        .prepareStatement("insert into testtable values(?,?,?,?)");
    for (int i = 1; i < 10; ++i) {
      pstmt1.setInt(1, i);
      pstmt1.setString(2, "desc" + i);
      pstmt1.setString(3, "Add" + i);
      pstmt1.setInt(4, i);
      assertEquals(1, pstmt1.executeUpdate());
    }
    conn.commit();
    PreparedStatement pstmt2 = conn
        .prepareStatement("update testtable set ID1 = ? where description = ?");
    for (int i = 1; i < 5; ++i) {
      pstmt2.setInt(1, i * 10);
      pstmt2.setString(2, "desc" + i);
      assertEquals(1, pstmt2.executeUpdate());
    }
    conn.commit();
    PreparedStatement pstmt3 = conn
        .prepareStatement("select ID1 from TestTable where description = ?");
    for (int i = 1; i < 5; ++i) {
      pstmt3.setString(1, "desc" + i);
      ResultSet rs = pstmt3.executeQuery();
      assertTrue(rs.next());
      assertEquals(i * 10, rs.getInt(1));
    }
    // Now a delete a row & reinsert the row but with changed data . The
    // deletion should go via bulk op route
    assertEquals(1,
        stmt.executeUpdate("delete from TESTTABLE where ADDRESS = 'Add5'"));
    // Insert a row corresponding to the row deleted with Address as Add5
    pstmt1.setInt(1, 5);
    pstmt1.setString(2, "desc.5");
    pstmt1.setString(3, "Add5");
    pstmt1.setInt(4, 5);
    assertEquals(1, pstmt1.executeUpdate());
    conn.commit();
    // PK delete
    stmt.executeUpdate("delete from TESTTABLE where ID = " + DELETED_KEY);
    conn.commit();
    blockForValidation();
    stopAsyncEventListener("WBCL1").run();
    validateResults(derbyStmt, "select * from testtable", this.netPort, true);
  } finally {
    cleanDerbyArtifacts(derbyStmt, new String[] { "validateTestEnd" },
        new String[] { "test_ok" }, new String[] { "TESTTABLE" }, derbyConn);
    // might get ShutdownExceptions in derby connection close
    addExpectedDerbyException(ShutdownException.class.getName());
    try {
      DriverManager.getConnection("jdbc:derby:;shutdown=true");
    } catch (SQLException sqle) {
      if (sqle.getMessage().indexOf("shutdown") == -1) {
        sqle.printStackTrace();
        throw sqle;
      }
    }
    if (server != null) {
      server.shutdown();
    }
  }
}
 
Example 4
Source File: SerialDBSynchronizerPart1DUnit.java    From gemfirexd-oss with Apache License 2.0 4 votes vote down vote up
public void testMemberSetForBulkOpDistributionForPRAndReplicatedTables()
    throws Exception {
  // create three server VMs. Define Gateway Hub on only one server VM.
  // The advise member set should return only one member & should not include
  // self.
  startServerVMs(2, -1, "SG0");
  startServerVMs(1, -1, "SG1");
  startClientVMs(1, 0, null);
  NetworkServerControl nsc = null;
  boolean tablesCreated = false;
  try {
    String derbyDbUrl = "jdbc:derby://"
        + InetAddress.getLocalHost().getHostName() + ':' + this.netPort
        + "/newDB;create=true;";
    if (TestUtil.currentUserName != null) {
      derbyDbUrl += ("user=" + TestUtil.currentUserName + ";password="
          + TestUtil.currentUserPassword + ';');
    }
    nsc = startNetworkServer();
    String tableDef = " create table TESTTABLE1 ( ID int not null primary key , test_bigint BIGINT, "
        + " test_boolean smallint )";
    clientSQLExecute(1, tableDef + "  AsyncEventListener (WBCL2) ");
    tablesCreated = true;
    Runnable runnable = getExecutorForWBCLConfiguration("SG1", "WBCL2",
        "com.pivotal.gemfirexd.callbacks.DBSynchronizer",
        "org.apache.derby.jdbc.ClientDriver", derbyDbUrl, true,
        Integer.valueOf(1), null, Boolean.TRUE, null, null, null, 100000, "", false);
    runnable.run();
    Runnable startWBCL = startAsyncEventListener("WBCL2");
    startWBCL.run();
    final String schemaName = getCurrentDefaultSchemaName();
    validate(schemaName + ".TESTTABLE1");
    // Create a replicated table
    tableDef = " create table TESTTABLE2 ( ID int not null primary key , test_bigint BIGINT, "
        + " test_boolean smallint )";
    clientSQLExecute(1, tableDef + "  replicate AsyncEventListener (WBCL2) ");
    validate(schemaName + ".TESTTABLE2");
  }
  finally {
    if (nsc != null) {
      nsc.shutdown();
    }
    if (tablesCreated) {
      clientSQLExecute(1, "drop table if exists TESTTABLE1");
      clientSQLExecute(1, "drop table if exists TESTTABLE2");
    }
    try {
      DriverManager.getConnection("jdbc:derby:;shutdown=true");
    }
    catch (SQLException sqle) {
      if (sqle.getMessage().indexOf("shutdown") == -1) {
        sqle.printStackTrace();
        throw sqle;
      }
    }
  }
}
 
Example 5
Source File: SerialDBSynchronizerPart2DUnit.java    From gemfirexd-oss with Apache License 2.0 4 votes vote down vote up
public void testTransactionalBehaviourOfAsyncEventListener_1()
    throws Exception {
  Connection derbyConn = null;
  Statement derbyStmt = null;
  NetworkServerControl server = null;
  try {
    server = startNetworkServer();
    createDerbyValidationArtefacts();
    String derbyDbUrl = "jdbc:derby://"
        + InetAddress.getLocalHost().getHostName() + ':' + this.netPort
        + "/newDB;create=true;";
    if (TestUtil.currentUserName != null) {
      derbyDbUrl += ("user=" + TestUtil.currentUserName + ";password="
          + TestUtil.currentUserPassword + ';');
    }
    derbyConn = DriverManager.getConnection(derbyDbUrl);
    // create schema
    derbyStmt = derbyConn.createStatement();
    // Create the controller VM as client which belongs to default server
    // group
    startClientVMs(1, 0, null);
    startServerVMs(1, -1, "SG1");
    // create table
    clientSQLExecute(1, "create table TESTTABLE (ID int not null "
        + "primary key, DESCRIPTION varchar(1024), ADDRESS varchar(1024), "
        + "ID1 int) AsyncEventListener (WBCL1)");

    Runnable runnable = getExecutorForWBCLConfiguration("SG1", "WBCL1",
        TXAsyncEventListener.class.getName(), null, derbyDbUrl, true,
        Integer.valueOf(1), null, Boolean.FALSE, null, null, null, 100000,
        null, false);
    runnable.run();
    Runnable startWBCL = startAsyncEventListener("WBCL1");
    clientExecute(1, startWBCL);
    Connection conn = TestUtil.jdbcConn;
    conn.setTransactionIsolation(Connection.TRANSACTION_READ_COMMITTED);
    conn.setAutoCommit(false);
    Statement stmt = conn.createStatement();
    // Do an insert in sql fabric. This will create a primary bucket on the
    // lone server VM with bucket ID =1

    stmt.executeUpdate("Insert into TESTTABLE values(114,'desc114','Add114',114)");

    stmt.executeUpdate("Insert into TESTTABLE values(1,'desc1','Add1',1)");
    stmt.executeUpdate("Insert into TESTTABLE values(227,'desc227','Add227',227)");
    stmt.executeUpdate("Insert into TESTTABLE values(340,'desc340','Add340',340)");
    conn.rollback();
    stmt.executeUpdate("Insert into TESTTABLE values(114,'desc114','Add114',114)");
    // Insert some more rows in gemfirexd
    stmt.executeUpdate("Insert into TESTTABLE values(1,'desc1','Add1',1)");
    stmt.executeUpdate("Insert into TESTTABLE values(2,'desc1','Add1',1)");
    stmt.executeUpdate("Insert into TESTTABLE values(224,'desc227','Add227',227)");
    stmt.executeUpdate("Insert into TESTTABLE values(331,'desc340','Add340',340)");
    conn.commit();
    // Bulk Update
    stmt.executeUpdate("update TESTTABLE set ID1 = ID1 +1 ");
    conn.rollback();
    // PK delete
    stmt.executeUpdate("delete from TESTTABLE where ID = " + DELETED_KEY);
    conn.commit();
    blockForValidation();
    stopAsyncEventListener("WBCL1").run();
    validateResults(derbyStmt, "select * from testtable", this.netPort, true);
  } finally {
    cleanDerbyArtifacts(derbyStmt, new String[] { "validateTestEnd" },
        new String[] { "test_ok" }, new String[] { "TESTTABLE" }, derbyConn);
    // might get ShutdownExceptions in derby connection close
    addExpectedDerbyException(ShutdownException.class.getName());
    try {
      DriverManager.getConnection("jdbc:derby:;shutdown=true");
    } catch (SQLException sqle) {
      if (sqle.getMessage().indexOf("shutdown") == -1) {
        sqle.printStackTrace();
        throw sqle;
      }
    }
    if (server != null) {
      server.shutdown();
    }
  }
}
 
Example 6
Source File: SerialDBSynchronizerPart1DUnit.java    From gemfirexd-oss with Apache License 2.0 4 votes vote down vote up
public void testBug42430_1() throws Exception {
  Connection derbyConn = null;
  Statement derbyStmt = null;
  Statement stmt = null;
  NetworkServerControl server = null;
  boolean tablesCreated = false;
  try {
    server = startNetworkServer();
    createDerbyValidationArtefacts();
    String derbyDbUrl = "jdbc:derby://"
        + InetAddress.getLocalHost().getHostName() + ':' + this.netPort
        + "/newDB;create=true;";
    if (TestUtil.currentUserName != null) {
      derbyDbUrl += ("user=" + TestUtil.currentUserName + ";password="
          + TestUtil.currentUserPassword + ';');
    }
    derbyConn = DriverManager.getConnection(derbyDbUrl);
    // create schema
    derbyStmt = derbyConn.createStatement();

    startServerVMs(2, -1, "SG1");

    // create table
    serverSQLExecute(1,
        "create table TESTTABLE (ID int not null primary key , "
            + "DESCRIPTION varchar(1024) , ADDRESS varchar(1024), ID1 int ) "
            + "AsyncEventListener (WBCL2) "
            + " partition by range (ID) (VALUES BETWEEN 0 AND 5,  "
            + "VALUES BETWEEN 5  AND 10 , VALUES BETWEEN 10  AND 20 )");

    tablesCreated = true;

    Runnable runnable = getExecutorForWBCLConfiguration("SG1", "WBCL2",
        "com.pivotal.gemfirexd.callbacks.DBSynchronizer",
        "org.apache.derby.jdbc.ClientDriver", derbyDbUrl, true,
        Integer.valueOf(1), null, Boolean.TRUE, null, null, null, 100000, "", false);
    serverExecute(1, runnable);
    Runnable startWBCL = startAsyncEventListener("WBCL2");
    serverExecute(1, startWBCL);
    startClientVMs(1, 0, null);
    Connection conn = TestUtil.jdbcConn;
    stmt = conn.createStatement();
    String str = "insert into TESTTABLE values";
    for (int i = 0; i < 20; ++i) {
      str += "(" + i + ", 'First', 'J 604'," + i + "),";
    }
    str = str.substring(0, str.length() - 1);
    stmt.executeUpdate(str);
    assertEquals(1,
        stmt.executeUpdate("delete from TESTTABLE where ID = " + DELETED_KEY));
    blockForValidation();
    // Now create a dumy client to allow validation
    startClientVMs(1, -1, "SG");
    validateResults(derbyStmt, "select * from testtable", this.netPort, true);
  }
  finally {
    ok = false;
    cleanDerbyArtifacts(derbyStmt, new String[] {}, new String[] {},
        new String[] { "TESTTABLE" }, derbyConn);
    if (tablesCreated) {
      clientSQLExecute(1, "drop table TESTTABLE");
      // derbyStmt.execute("drop procedure validateTestEnd");
    }
    try {
      DriverManager.getConnection("jdbc:derby:;shutdown=true");
    }
    catch (SQLException sqle) {
      if (sqle.getMessage().indexOf("shutdown") == -1) {
        sqle.printStackTrace();
        throw sqle;
      }
    }
    if (server != null) {
      server.shutdown();
    }
  }
}
 
Example 7
Source File: SerialDBSynchronizerPart1DUnit.java    From gemfirexd-oss with Apache License 2.0 4 votes vote down vote up
public void testDBSynchronizerRemovalBehaviour() throws Exception {
  Statement derbyStmt = null;
  Connection derbyConn = null;
  NetworkServerControl server = null;
  try {
    String derbyDbUrl = "jdbc:derby://"
        + InetAddress.getLocalHost().getHostName() + ':' + this.netPort
        + "/newDB;create=true;";
    if (TestUtil.currentUserName != null) {
      derbyDbUrl += ("user=" + TestUtil.currentUserName + ";password="
          + TestUtil.currentUserPassword + ';');
    }
    server = startNetworkServer();
    addExpectedDerbyException(".*derby\\.daemons\\] \\(DATABASE = newDB\\), \\(DRDAID.*");
    createDerbyValidationArtefacts();
    derbyConn = DriverManager.getConnection(derbyDbUrl);

    derbyDbUrl = "jdbc:derby://" + InetAddress.getLocalHost().getHostName()
        + ':' + this.netPort + "/newDB;";
    if (TestUtil.currentUserName != null) {
      derbyDbUrl += ("user=" + TestUtil.currentUserName + ";password="
          + TestUtil.currentUserPassword + ';');
    }
    // create schema
    derbyStmt = derbyConn.createStatement();
    // Create the controller VM as client which belongs to default server
    // group

    startClientVMs(1, 0, null);
    startServerVMs(3, -1, "SG1");
    // create table
    clientSQLExecute(1,
        "create table TESTTABLE (ID int not null primary key, "
            + "DESCRIPTION varchar(1024) , ADDRESS varchar(1024), ID1 int) "
            + "AsyncEventListener (WBCL1)");

    Runnable createConfig = getExecutorForWBCLConfiguration("SG1", "WBCL1",
        "com.pivotal.gemfirexd.callbacks.DBSynchronizer",
        "org.apache.derby.jdbc.ClientDriver", derbyDbUrl, true,
        Integer.valueOf(1), null, Boolean.FALSE, null, null, null, 100000, "", false);
    createConfig.run();
    Runnable startWBCL = startAsyncEventListener("WBCL1");
    clientExecute(1, startWBCL);
    // stop network server so that events cannot be dispatched
    server.shutdown();
    addExpectedException(null, new int[] { 1, 2, 3 },
        java.sql.SQLNonTransientConnectionException.class);

    addExpectedException(null, new int[] { 1, 2, 3 },
        com.pivotal.gemfirexd.internal.engine.jdbc.GemFireXDRuntimeException.class);
    // Do an insert in sql fabric
    clientSQLExecute(1, "Insert into TESTTABLE values(1,'desc1','Add1',1)");
    clientSQLExecute(1, "Insert into TESTTABLE values(2,'desc2','Add2',2)");
    clientSQLExecute(1, "Insert into TESTTABLE values(3,'desc3','Add3',3)");
    clientSQLExecute(1, "Insert into TESTTABLE values(4,'desc4','Add4',4)");
    clientSQLExecute(1, "Insert into TESTTABLE values(5,'desc5','Add5',5)");
    clientSQLExecute(1, "Insert into TESTTABLE values(6,'desc6','Add6',6)");
    // Bulk Update
    stopAsyncEventListener("WBCL1").run();
    Thread.sleep(5000);
    clientSQLExecute(1, "alter table testtable set AsyncEventListener ()");
    // Now drop WBCL.
    Runnable remove = dropAsyncEventListener("WBCL1");
    remove.run();
    clientSQLExecute(1, "alter table testtable set AsyncEventListener (WBCL1)");
    // Recreate the configuration
    server = startNetworkServer();
    createConfig.run();

    // check that queue is empty.
    Callable<?> checkQueueEmpty = getExecutorToCheckQueueEmpty("WBCL1");
    assertTrue(((Boolean)serverExecute(1, checkQueueEmpty)).booleanValue());
    assertTrue(((Boolean)serverExecute(2, checkQueueEmpty)).booleanValue());
    assertTrue(((Boolean)serverExecute(3, checkQueueEmpty)).booleanValue());

  }
  finally {

    cleanDerbyArtifacts(derbyStmt, new String[] {}, new String[] {},
        new String[] { "TESTTABLE" }, derbyConn);
    // might get ShutdownExceptions in derby connection close
    addExpectedDerbyException(ShutdownException.class.getName());
    try {
      DriverManager.getConnection("jdbc:derby:;shutdown=true");
    }
    catch (SQLException sqle) {
      if (sqle.getMessage().indexOf("shutdown") == -1) {
        sqle.printStackTrace();
        throw sqle;
      }
    }
    if (server != null) {
      try {
        server.shutdown();
      }
      catch (Exception ex) {
        getLogWriter().error("unexpected exception", ex);
      }
    }
  }
}
 
Example 8
Source File: SerialDBSynchronizerPart1DUnit.java    From gemfirexd-oss with Apache License 2.0 4 votes vote down vote up
public void testBug42430_1() throws Exception {
  Connection derbyConn = null;
  Statement derbyStmt = null;
  Statement stmt = null;
  NetworkServerControl server = null;
  boolean tablesCreated = false;
  try {
    server = startNetworkServer();
    createDerbyValidationArtefacts();
    String derbyDbUrl = "jdbc:derby://"
        + InetAddress.getLocalHost().getHostName() + ':' + this.netPort
        + "/newDB;create=true;";
    if (TestUtil.currentUserName != null) {
      derbyDbUrl += ("user=" + TestUtil.currentUserName + ";password="
          + TestUtil.currentUserPassword + ';');
    }
    derbyConn = DriverManager.getConnection(derbyDbUrl);
    // create schema
    derbyStmt = derbyConn.createStatement();

    startServerVMs(2, -1, "SG1");

    // create table
    serverSQLExecute(1,
        "create table TESTTABLE (ID int not null primary key , "
            + "DESCRIPTION varchar(1024) , ADDRESS varchar(1024), ID1 int ) "
            + "AsyncEventListener (WBCL2) "
            + " partition by range (ID) (VALUES BETWEEN 0 AND 5,  "
            + "VALUES BETWEEN 5  AND 10 , VALUES BETWEEN 10  AND 20 )");

    tablesCreated = true;

    Runnable runnable = getExecutorForWBCLConfiguration("SG1", "WBCL2",
        "com.pivotal.gemfirexd.callbacks.DBSynchronizer",
        "org.apache.derby.jdbc.ClientDriver", derbyDbUrl, true,
        Integer.valueOf(1), null, Boolean.TRUE, null, null, null, 100000, "", false);
    serverExecute(1, runnable);
    Runnable startWBCL = startAsyncEventListener("WBCL2");
    serverExecute(1, startWBCL);
    startClientVMs(1, 0, null);
    Connection conn = TestUtil.jdbcConn;
    stmt = conn.createStatement();
    String str = "insert into TESTTABLE values";
    for (int i = 0; i < 20; ++i) {
      str += "(" + i + ", 'First', 'J 604'," + i + "),";
    }
    str = str.substring(0, str.length() - 1);
    stmt.executeUpdate(str);
    assertEquals(1,
        stmt.executeUpdate("delete from TESTTABLE where ID = " + DELETED_KEY));
    blockForValidation();
    // Now create a dumy client to allow validation
    startClientVMs(1, -1, "SG");
    validateResults(derbyStmt, "select * from testtable", this.netPort, true);
  }
  finally {
    ok = false;
    cleanDerbyArtifacts(derbyStmt, new String[] {}, new String[] {},
        new String[] { "TESTTABLE" }, derbyConn);
    if (tablesCreated) {
      clientSQLExecute(1, "drop table TESTTABLE");
      // derbyStmt.execute("drop procedure validateTestEnd");
    }
    try {
      DriverManager.getConnection("jdbc:derby:;shutdown=true");
    }
    catch (SQLException sqle) {
      if (sqle.getMessage().indexOf("shutdown") == -1) {
        sqle.printStackTrace();
        throw sqle;
      }
    }
    if (server != null) {
      server.shutdown();
    }
  }
}
 
Example 9
Source File: SerialDBSynchronizerPart2DUnit.java    From gemfirexd-oss with Apache License 2.0 4 votes vote down vote up
public void testDBSynchronizerAfterTruncateTable_Partition() throws Exception {
  Connection derbyConn = null;
  Statement derbyStmt = null;
  NetworkServerControl server = null;
  try {
    server = startNetworkServer();
    createDerbyValidationArtefacts();
    String derbyDbUrl = "jdbc:derby://"
        + InetAddress.getLocalHost().getHostName() + ':' + this.netPort
        + "/newDB;create=true;";
    if (TestUtil.currentUserName != null) {
      derbyDbUrl += ("user=" + TestUtil.currentUserName + ";password="
          + TestUtil.currentUserPassword + ';');
    }
    derbyConn = DriverManager.getConnection(derbyDbUrl);
    // create schema
    derbyStmt = derbyConn.createStatement();

    // Create the controller VM as client which belongs to default server
    // group
    startClientVMs(1, 0, null);
    startServerVMs(1, -1, "SG1");
    // create table
    clientSQLExecute(1,
        "create table TESTTABLE (ID int not null primary key , "
            + "DESCRIPTION varchar(1024) , ADDRESS varchar(1024), ID1 int )"
            + " partition by primary key AsyncEventListener (WBCL1) ");

    Runnable runnable = getExecutorForWBCLConfiguration("SG1", "WBCL1",
        "com.pivotal.gemfirexd.callbacks.DBSynchronizer",
        "org.apache.derby.jdbc.ClientDriver", derbyDbUrl, true,
        Integer.valueOf(1), null, Boolean.FALSE, null, null, null, 100000,
        "org.apache.derby.jdbc.ClientDriver," + derbyDbUrl, false);
    runnable.run();
    Runnable startWBCL = startAsyncEventListener("WBCL1");
    clientExecute(1, startWBCL);
    Connection conn = TestUtil.jdbcConn;
    conn.setTransactionIsolation(Connection.TRANSACTION_READ_COMMITTED);
    Statement stmt = conn.createStatement();
    // Do an insert in sql fabric. This will create a primary bucket on the
    // lone server VM
    // with bucket ID =1

    stmt.executeUpdate("Insert into TESTTABLE values(1114,'desc114','Add114',114)");
    stmt.executeUpdate("Insert into TESTTABLE values(11,'desc1','Add1',1)");
    stmt.executeUpdate("Insert into TESTTABLE values(1227,'desc227','Add227',227)");
    stmt.executeUpdate("Insert into TESTTABLE values(1340,'desc340','Add340',340)");
    conn.commit();

    stmt.executeUpdate("truncate table TESTTABLE");
    conn.commit();
    // assert empty table
    ResultSet rs = stmt.executeQuery("select count(*) from TESTTABLE");
    JDBC.assertSingleValueResultSet(rs, "0");

    // delete everything in GemFireXD again, because truncate table as DDL won't
    // be propagated to Derby
    // However, the following delete as DML will be propagated to Derby to do
    // something equivalent to truncate table
    stmt.executeUpdate("delete from TESTTABLE");

    // Insert some more rows in gemfirexd
    stmt.executeUpdate("Insert into TESTTABLE values(114,'desc114','Add114',114)");
    stmt.executeUpdate("Insert into TESTTABLE values(1,'desc1','Add1',1)");
    stmt.executeUpdate("Insert into TESTTABLE values(2,'desc1','Add1',1)");
    stmt.executeUpdate("Insert into TESTTABLE values(224,'desc227','Add227',227)");
    stmt.executeUpdate("Insert into TESTTABLE values(331,'desc340','Add340',340)");
    conn.commit();
    // Bulk Update
    stmt.executeUpdate("update TESTTABLE set ID1 = ID1 +1 ");
    conn.rollback();
    // PK delete
    stmt.executeUpdate("delete from TESTTABLE where ID = " + DELETED_KEY);
    conn.commit();

    blockForValidation();
    stopAsyncEventListener("WBCL1").run();
    validateResults(derbyStmt, "select * from testtable", this.netPort, true);
  } finally {
    cleanDerbyArtifacts(derbyStmt, new String[] { "validateTestEnd" },
        new String[] { "test_ok" }, new String[] { "TESTTABLE" }, derbyConn);
    // might get ShutdownExceptions in derby connection close
    addExpectedDerbyException(ShutdownException.class.getName());
    try {
      DriverManager.getConnection("jdbc:derby:;shutdown=true");
    } catch (SQLException sqle) {
      if (sqle.getMessage().indexOf("shutdown") == -1) {
        sqle.printStackTrace();
        throw sqle;
      }
    }
    if (server != null) {
      server.shutdown();
    }
  }
}
 
Example 10
Source File: SerialDBSynchronizerPart1DUnit.java    From gemfirexd-oss with Apache License 2.0 4 votes vote down vote up
public void testDBSynchronizerRemovalBehaviour() throws Exception {
  Statement derbyStmt = null;
  Connection derbyConn = null;
  NetworkServerControl server = null;
  try {
    String derbyDbUrl = "jdbc:derby://"
        + InetAddress.getLocalHost().getHostName() + ':' + this.netPort
        + "/newDB;create=true;";
    if (TestUtil.currentUserName != null) {
      derbyDbUrl += ("user=" + TestUtil.currentUserName + ";password="
          + TestUtil.currentUserPassword + ';');
    }
    server = startNetworkServer();
    addExpectedDerbyException(".*derby\\.daemons\\] \\(DATABASE = newDB\\), \\(DRDAID.*");
    createDerbyValidationArtefacts();
    derbyConn = DriverManager.getConnection(derbyDbUrl);

    derbyDbUrl = "jdbc:derby://" + InetAddress.getLocalHost().getHostName()
        + ':' + this.netPort + "/newDB;";
    if (TestUtil.currentUserName != null) {
      derbyDbUrl += ("user=" + TestUtil.currentUserName + ";password="
          + TestUtil.currentUserPassword + ';');
    }
    // create schema
    derbyStmt = derbyConn.createStatement();
    // Create the controller VM as client which belongs to default server
    // group

    startClientVMs(1, 0, null);
    startServerVMs(3, -1, "SG1");
    // create table
    clientSQLExecute(1,
        "create table TESTTABLE (ID int not null primary key, "
            + "DESCRIPTION varchar(1024) , ADDRESS varchar(1024), ID1 int) "
            + "AsyncEventListener (WBCL1)");

    Runnable createConfig = getExecutorForWBCLConfiguration("SG1", "WBCL1",
        "com.pivotal.gemfirexd.callbacks.DBSynchronizer",
        "org.apache.derby.jdbc.ClientDriver", derbyDbUrl, true,
        Integer.valueOf(1), null, Boolean.FALSE, null, null, null, 100000, "", false);
    createConfig.run();
    Runnable startWBCL = startAsyncEventListener("WBCL1");
    clientExecute(1, startWBCL);
    // stop network server so that events cannot be dispatched
    server.shutdown();
    addExpectedException(null, new int[] { 1, 2, 3 },
        java.sql.SQLNonTransientConnectionException.class);

    addExpectedException(null, new int[] { 1, 2, 3 },
        com.pivotal.gemfirexd.internal.engine.jdbc.GemFireXDRuntimeException.class);
    // Do an insert in sql fabric
    clientSQLExecute(1, "Insert into TESTTABLE values(1,'desc1','Add1',1)");
    clientSQLExecute(1, "Insert into TESTTABLE values(2,'desc2','Add2',2)");
    clientSQLExecute(1, "Insert into TESTTABLE values(3,'desc3','Add3',3)");
    clientSQLExecute(1, "Insert into TESTTABLE values(4,'desc4','Add4',4)");
    clientSQLExecute(1, "Insert into TESTTABLE values(5,'desc5','Add5',5)");
    clientSQLExecute(1, "Insert into TESTTABLE values(6,'desc6','Add6',6)");
    // Bulk Update
    stopAsyncEventListener("WBCL1").run();
    Thread.sleep(5000);
    clientSQLExecute(1, "alter table testtable set AsyncEventListener ()");
    // Now drop WBCL.
    Runnable remove = dropAsyncEventListener("WBCL1");
    remove.run();
    clientSQLExecute(1, "alter table testtable set AsyncEventListener (WBCL1)");
    // Recreate the configuration
    server = startNetworkServer();
    createConfig.run();

    // check that queue is empty.
    Callable<?> checkQueueEmpty = getExecutorToCheckQueueEmpty("WBCL1");
    assertTrue(((Boolean)serverExecute(1, checkQueueEmpty)).booleanValue());
    assertTrue(((Boolean)serverExecute(2, checkQueueEmpty)).booleanValue());
    assertTrue(((Boolean)serverExecute(3, checkQueueEmpty)).booleanValue());

  }
  finally {

    cleanDerbyArtifacts(derbyStmt, new String[] {}, new String[] {},
        new String[] { "TESTTABLE" }, derbyConn);
    // might get ShutdownExceptions in derby connection close
    addExpectedDerbyException(ShutdownException.class.getName());
    try {
      DriverManager.getConnection("jdbc:derby:;shutdown=true");
    }
    catch (SQLException sqle) {
      if (sqle.getMessage().indexOf("shutdown") == -1) {
        sqle.printStackTrace();
        throw sqle;
      }
    }
    if (server != null) {
      try {
        server.shutdown();
      }
      catch (Exception ex) {
        getLogWriter().error("unexpected exception", ex);
      }
    }
  }
}
 
Example 11
Source File: SerialDBSynchronizerPart2DUnit.java    From gemfirexd-oss with Apache License 2.0 4 votes vote down vote up
public void testTransactionalBehaviourOfBug42706_2() throws Exception {
  Connection derbyConn = null;
  Statement derbyStmt = null;
  NetworkServerControl server = null;
  boolean tablesCreated = false;
  try {
    server = startNetworkServer();
    createDerbyValidationArtefacts();
    String derbyDbUrl = "jdbc:derby://"
        + InetAddress.getLocalHost().getHostName() + ':' + this.netPort
        + "/newDB;create=true;";
    if (TestUtil.currentUserName != null) {
      derbyDbUrl += ("user=" + TestUtil.currentUserName + ";password="
          + TestUtil.currentUserPassword + ';');
    }
    derbyConn = DriverManager.getConnection(derbyDbUrl);
    // create schema
    derbyStmt = derbyConn.createStatement();

    startServerVMs(2, -1, "SG1");

    // create table
    serverSQLExecute(1,
        "create table TESTTABLE (ID int not null primary key , "
            + "DESCRIPTION varchar(1024) , ADDRESS varchar(1024), ID1 int ) "
            + "AsyncEventListener (WBCL2)  ");

    tablesCreated = true;

    Runnable runnable = getExecutorForWBCLConfiguration("SG1", "WBCL2",
        "com.pivotal.gemfirexd.callbacks.DBSynchronizer",
        "org.apache.derby.jdbc.ClientDriver", derbyDbUrl, true,
        Integer.valueOf(1), null, Boolean.TRUE, null, null, null, 100000,
        "org.apache.derby.jdbc.ClientDriver," + derbyDbUrl, false);
    serverExecute(1, runnable);
    Runnable startWBCL = startAsyncEventListener("WBCL2");
    serverExecute(1, startWBCL);
    startClientVMs(1, 0, null);
    Connection conn = TestUtil.jdbcConn;
    String schema = ((EmbedConnection)TestUtil.jdbcConn)
        .getLanguageConnection().getCurrentSchemaName();
    if (schema == null) {
      schema = Misc.getDefaultSchemaName(((EmbedConnection)TestUtil.jdbcConn)
          .getLanguageConnection());
    }

    GfxdCallbacksTest.addLoader(schema, "TESTTABLE",
        "com.pivotal.gemfirexd.dbsync.DBSynchronizerTestBase$GfxdTestRowLoader",
        "");

    conn.setTransactionIsolation(Connection.TRANSACTION_READ_COMMITTED);
    conn.createStatement();

    sqlExecuteVerify(new int[] { 1 }, null,
        "select ID from TESTTABLE where ID = 1", null, null);

    sqlExecuteVerify(new int[] { 1 }, null,
        "select ID from TESTTABLE where ID = 2", null, null);

    sqlExecuteVerify(new int[] { 1 }, null,
        "select ID from TESTTABLE where ID = 3", null, null);

    conn.commit();

    SerializableCallable queueChecker = getEmptyQueueChecker();
    Boolean retVal = (Boolean)serverExecute(1, queueChecker);
    assertTrue(retVal.booleanValue());

    retVal = (Boolean)serverExecute(2, queueChecker);
    assertTrue(retVal.booleanValue());

    ResultSet rs = derbyStmt.executeQuery("select * from testtable ");
    assertFalse(rs.next());

  } finally {
    ok = false;
    derbyStmt.executeUpdate("delete from testtable");
    cleanDerbyArtifacts(derbyStmt, new String[] {}, new String[] {},
        new String[] { "TESTTABLE" }, derbyConn);
    if (tablesCreated) {
      clientSQLExecute(1, "drop table TESTTABLE");
      // derbyStmt.execute("drop procedure validateTestEnd");
    }
    try {
      DriverManager.getConnection("jdbc:derby:;shutdown=true");
    } catch (SQLException sqle) {
      if (sqle.getMessage().indexOf("shutdown") == -1) {
        sqle.printStackTrace();
        throw sqle;
      }
    }
    if (server != null) {
      server.shutdown();
    }
  }
}
 
Example 12
Source File: SerialDBSynchronizerPart2DUnit.java    From gemfirexd-oss with Apache License 2.0 4 votes vote down vote up
public void testTransactionalBehaviourOfBug42706_1() throws Exception {
  Connection derbyConn = null;
  Statement derbyStmt = null;
  NetworkServerControl server = null;
  boolean tablesCreated = false;
  try {
    server = startNetworkServer();
    createDerbyValidationArtefacts();
    String derbyDbUrl = "jdbc:derby://"
        + InetAddress.getLocalHost().getHostName() + ':' + this.netPort
        + "/newDB;create=true;";
    if (TestUtil.currentUserName != null) {
      derbyDbUrl += ("user=" + TestUtil.currentUserName + ";password="
          + TestUtil.currentUserPassword + ';');
    }
    derbyConn = DriverManager.getConnection(derbyDbUrl);
    // create schema
    derbyStmt = derbyConn.createStatement();

    startServerVMs(2, -1, "SG1");

    // create table
    serverSQLExecute(1,
        "create table TESTTABLE (ID int not null primary key , "
            + "DESCRIPTION varchar(1024) , ADDRESS varchar(1024), ID1 int ) "
            + "AsyncEventListener (WBCL2)  replicate ");

    tablesCreated = true;

    Runnable runnable = getExecutorForWBCLConfiguration("SG1", "WBCL2",
        "com.pivotal.gemfirexd.callbacks.DBSynchronizer",
        "org.apache.derby.jdbc.ClientDriver", derbyDbUrl, true,
        Integer.valueOf(1), null, Boolean.TRUE, null, null, null, 100000,
        "org.apache.derby.jdbc.ClientDriver," + derbyDbUrl, false);
    serverExecute(1, runnable);
    Runnable startWBCL = startAsyncEventListener("WBCL2");
    serverExecute(1, startWBCL);
    startClientVMs(1, 0, null);
    Connection conn = TestUtil.jdbcConn;
    String schema = ((EmbedConnection)TestUtil.jdbcConn)
        .getLanguageConnection().getCurrentSchemaName();
    if (schema == null) {
      schema = Misc.getDefaultSchemaName(((EmbedConnection)TestUtil.jdbcConn)
          .getLanguageConnection());
    }

    GfxdCallbacksTest.addLoader(schema, "TESTTABLE",
        "com.pivotal.gemfirexd.dbsync.DBSynchronizerTestBase$GfxdTestRowLoader",
        "");

    conn.setTransactionIsolation(Connection.TRANSACTION_READ_COMMITTED);
    conn.createStatement();

    sqlExecuteVerify(new int[] { 1 }, null,
        "select ID from TESTTABLE where ID = 1", null, null);

    sqlExecuteVerify(new int[] { 1 }, null,
        "select ID from TESTTABLE where ID = 2", null, null);

    sqlExecuteVerify(new int[] { 1 }, null,
        "select ID from TESTTABLE where ID = 3", null, null);

    conn.commit();

    SerializableCallable queueChecker = getEmptyQueueChecker();
    Boolean retVal = (Boolean)serverExecute(1, queueChecker);
    assertTrue(retVal.booleanValue());

    retVal = (Boolean)serverExecute(2, queueChecker);
    assertTrue(retVal.booleanValue());

    ResultSet rs = derbyStmt.executeQuery("select * from testtable ");
    assertFalse(rs.next());

  } finally {
    ok = false;
    derbyStmt.executeUpdate("delete from testtable");
    cleanDerbyArtifacts(derbyStmt, new String[] {}, new String[] {},
        new String[] { "TESTTABLE" }, derbyConn);
    if (tablesCreated) {
      clientSQLExecute(1, "drop table TESTTABLE");
      // derbyStmt.execute("drop procedure validateTestEnd");
    }
    try {
      DriverManager.getConnection("jdbc:derby:;shutdown=true");
    } catch (SQLException sqle) {
      if (sqle.getMessage().indexOf("shutdown") == -1) {
        sqle.printStackTrace();
        throw sqle;
      }
    }
    if (server != null) {
      server.shutdown();
    }
  }
}
 
Example 13
Source File: SerialDBSynchronizerPart1DUnit.java    From gemfirexd-oss with Apache License 2.0 4 votes vote down vote up
public void testBug42430_2() throws Exception {
  Connection derbyConn = null;
  Statement derbyStmt = null;
  Statement stmt = null;
  NetworkServerControl server = null;
  boolean tablesCreated = false;
  try {
    server = startNetworkServer();
    createDerbyValidationArtefacts();
    String derbyDbUrl = "jdbc:derby://"
        + InetAddress.getLocalHost().getHostName() + ':' + this.netPort
        + "/newDB;create=true;";
    if (TestUtil.currentUserName != null) {
      derbyDbUrl += ("user=" + TestUtil.currentUserName + ";password="
          + TestUtil.currentUserPassword + ';');
    }
    derbyConn = DriverManager.getConnection(derbyDbUrl);
    // create schema
    derbyStmt = derbyConn.createStatement();

    startServerVMs(2, -1, "SG1");

    // create table
    serverSQLExecute(1,
        "create table TESTTABLE (ID int not null primary key , "
            + "DESCRIPTION varchar(1024) , ADDRESS varchar(1024), ID1 int ) "
            + "AsyncEventListener (WBCL2)  replicate ");

    tablesCreated = true;

    Runnable runnable = getExecutorForWBCLConfiguration("SG1", "WBCL2",
        "com.pivotal.gemfirexd.callbacks.DBSynchronizer",
        "org.apache.derby.jdbc.ClientDriver", derbyDbUrl, true,
        Integer.valueOf(1), null, Boolean.TRUE, null, null, null, 100000, "", false);
    serverExecute(1, runnable);
    Runnable startWBCL = startAsyncEventListener("WBCL2");
    serverExecute(1, startWBCL);
    startClientVMs(1, 0, null);
    Connection conn = TestUtil.jdbcConn;
    stmt = conn.createStatement();
    String str = "insert into TESTTABLE values";
    for (int i = 0; i < 20; ++i) {
      str += "(" + i + ", 'First', 'J 604'," + i + "),";
    }
    str = str.substring(0, str.length() - 1);
    stmt.executeUpdate(str);
    assertEquals(1,
        stmt.executeUpdate("delete from TESTTABLE where ID = " + DELETED_KEY));
    blockForValidation();
    // Now create a dumy client to allow validation
    startClientVMs(1, -1, "SG");
    validateResults(derbyStmt, "select * from testtable", this.netPort, true);
  }
  finally {
    ok = false;
    cleanDerbyArtifacts(derbyStmt, new String[] {}, new String[] {},
        new String[] { "TESTTABLE" }, derbyConn);
    if (tablesCreated) {
      clientSQLExecute(1, "drop table TESTTABLE");
      // derbyStmt.execute("drop procedure validateTestEnd");
    }
    try {
      DriverManager.getConnection("jdbc:derby:;shutdown=true");
    }
    catch (SQLException sqle) {
      if (sqle.getMessage().indexOf("shutdown") == -1) {
        sqle.printStackTrace();
        throw sqle;
      }
    }
    if (server != null) {
      server.shutdown();
    }
  }
}
 
Example 14
Source File: SerialDBSynchronizerPart2DUnit.java    From gemfirexd-oss with Apache License 2.0 4 votes vote down vote up
public void testBug42706_2() throws Exception {

    Connection derbyConn = null;
    Statement derbyStmt = null;
    NetworkServerControl server = null;
    boolean tablesCreated = false;
    try {
      server = startNetworkServer();
      createDerbyValidationArtefacts();
      String derbyDbUrl = "jdbc:derby://"
          + InetAddress.getLocalHost().getHostName() + ':' + this.netPort
          + "/newDB;create=true;";
      if (TestUtil.currentUserName != null) {
        derbyDbUrl += ("user=" + TestUtil.currentUserName + ";password="
            + TestUtil.currentUserPassword + ';');
      }
      derbyConn = DriverManager.getConnection(derbyDbUrl);
      // create schema
      derbyStmt = derbyConn.createStatement();

      startServerVMs(2, -1, "SG1");

      // create table
      serverSQLExecute(1, "create table TESTTABLE "
          + "(ID int not null primary key, DESCRIPTION varchar(1024), "
          + "ADDRESS varchar(1024), ID1 int ) partition by column(ID1) "
          + "AsyncEventListener (WBCL2)   ");

      tablesCreated = true;

      Runnable runnable = getExecutorForWBCLConfiguration("SG1", "WBCL2",
          "com.pivotal.gemfirexd.callbacks.DBSynchronizer",
          "org.apache.derby.jdbc.ClientDriver", derbyDbUrl, true,
          Integer.valueOf(1), null, Boolean.TRUE, null, null, null, 100000,
          "org.apache.derby.jdbc.ClientDriver," + derbyDbUrl, false);
      serverExecute(1, runnable);
      Runnable startWBCL = startAsyncEventListener("WBCL2");
      serverExecute(1, startWBCL);
      startClientVMs(1, 0, null);
      Connection conn = TestUtil.jdbcConn;
      String schema = ((EmbedConnection)TestUtil.jdbcConn)
          .getLanguageConnection().getCurrentSchemaName();
      if (schema == null) {
        schema = Misc.getDefaultSchemaName(((EmbedConnection)TestUtil.jdbcConn)
            .getLanguageConnection());
      }
      conn.createStatement();

      GfxdCallbacksTest.addLoader(schema, "TESTTABLE",
          "com.pivotal.gemfirexd.dbsync.DBSynchronizerTestBase$GfxdTestRowLoader",
          "");
      sqlExecuteVerify(new int[] { 1 }, null,
          "select ID from TESTTABLE where ID = 1", null, null);

      sqlExecuteVerify(new int[] { 1 }, null,
          "select ID from TESTTABLE where ID = 2", null, null);

      sqlExecuteVerify(new int[] { 1 }, null,
          "select ID from TESTTABLE where ID = 3", null, null);

      SerializableCallable queueChecker = getEmptyQueueChecker();
      Boolean retVal = (Boolean)serverExecute(1, queueChecker);
      assertTrue(retVal.booleanValue());

      retVal = (Boolean)serverExecute(2, queueChecker);
      assertTrue(retVal.booleanValue());

      ResultSet rs = derbyStmt.executeQuery("select * from testtable ");
      assertFalse(rs.next());

    } finally {
      ok = false;
      if (derbyStmt != null) {
        derbyStmt.executeUpdate("delete from testtable");
        cleanDerbyArtifacts(derbyStmt, new String[] {}, new String[] {},
            new String[] { "TESTTABLE" }, derbyConn);
      }
      if (tablesCreated) {
        clientSQLExecute(1, "drop table TESTTABLE");
        // derbyStmt.execute("drop procedure validateTestEnd");
      }
      try {
        DriverManager.getConnection("jdbc:derby:;shutdown=true");
      } catch (SQLException sqle) {
        if (sqle.getMessage().indexOf("shutdown") == -1) {
          sqle.printStackTrace();
          throw sqle;
        }
      }
      if (server != null) {
        server.shutdown();
      }
    }
  }
 
Example 15
Source File: SerialDBSynchronizerPart2DUnit.java    From gemfirexd-oss with Apache License 2.0 4 votes vote down vote up
public void testBug42706_1() throws Exception {

    Connection derbyConn = null;
    Statement derbyStmt = null;
    NetworkServerControl server = null;
    boolean tablesCreated = false;
    try {
      server = startNetworkServer();
      createDerbyValidationArtefacts();
      String derbyDbUrl = "jdbc:derby://"
          + InetAddress.getLocalHost().getHostName() + ':' + this.netPort
          + "/newDB;create=true;";
      if (TestUtil.currentUserName != null) {
        derbyDbUrl += ("user=" + TestUtil.currentUserName + ";password="
            + TestUtil.currentUserPassword + ';');
      }
      derbyConn = DriverManager.getConnection(derbyDbUrl);
      // create schema
      derbyStmt = derbyConn.createStatement();

      startServerVMs(2, -1, "SG1");

      // create table
      serverSQLExecute(1,
          "create table TESTTABLE (ID int not null primary key , "
              + "DESCRIPTION varchar(1024) , ADDRESS varchar(1024), ID1 int ) "
              + "AsyncEventListener (WBCL2)  replicate ");

      tablesCreated = true;

      Runnable runnable = getExecutorForWBCLConfiguration("SG1", "WBCL2",
          "com.pivotal.gemfirexd.callbacks.DBSynchronizer",
          "org.apache.derby.jdbc.ClientDriver", derbyDbUrl, true,
          Integer.valueOf(1), null, Boolean.TRUE, null, null, null, 100000,
          "org.apache.derby.jdbc.ClientDriver," + derbyDbUrl, false);
      serverExecute(1, runnable);
      Runnable startWBCL = startAsyncEventListener("WBCL2");
      serverExecute(1, startWBCL);
      startClientVMs(1, 0, null);
      Connection conn = TestUtil.jdbcConn;
      String schema = ((EmbedConnection)TestUtil.jdbcConn)
          .getLanguageConnection().getCurrentSchemaName();
      if (schema == null) {
        schema = Misc.getDefaultSchemaName(((EmbedConnection)TestUtil.jdbcConn)
            .getLanguageConnection());
      }
      conn.createStatement();

      GfxdCallbacksTest.addLoader(schema, "TESTTABLE",
          "com.pivotal.gemfirexd.dbsync.DBSynchronizerTestBase$GfxdTestRowLoader",
          "");
      sqlExecuteVerify(new int[] { 1 }, null,
          "select ID from TESTTABLE where ID = 1", null, null);

      sqlExecuteVerify(new int[] { 1 }, null,
          "select ID from TESTTABLE where ID = 2", null, null);

      sqlExecuteVerify(new int[] { 1 }, null,
          "select ID from TESTTABLE where ID = 3", null, null);

      SerializableCallable queueChecker = getEmptyQueueChecker();
      Boolean retVal = (Boolean)serverExecute(1, queueChecker);
      assertTrue(retVal.booleanValue());

      retVal = (Boolean)serverExecute(2, queueChecker);
      assertTrue(retVal.booleanValue());

      ResultSet rs = derbyStmt.executeQuery("select * from testtable ");
      assertFalse(rs.next());

    } finally {
      ok = false;
      derbyStmt.executeUpdate("delete from testtable");
      cleanDerbyArtifacts(derbyStmt, new String[] {}, new String[] {},
          new String[] { "TESTTABLE" }, derbyConn);
      if (tablesCreated) {
        clientSQLExecute(1, "drop table TESTTABLE");
        // derbyStmt.execute("drop procedure validateTestEnd");
      }
      try {
        DriverManager.getConnection("jdbc:derby:;shutdown=true");
      } catch (SQLException sqle) {
        if (sqle.getMessage().indexOf("shutdown") == -1) {
          sqle.printStackTrace();
          throw sqle;
        }
      }
      if (server != null) {
        server.shutdown();
      }
    }
  }
 
Example 16
Source File: SerialDBSynchronizerPart2DUnit.java    From gemfirexd-oss with Apache License 2.0 4 votes vote down vote up
public void testBug42706_1() throws Exception {

    Connection derbyConn = null;
    Statement derbyStmt = null;
    NetworkServerControl server = null;
    boolean tablesCreated = false;
    try {
      server = startNetworkServer();
      createDerbyValidationArtefacts();
      String derbyDbUrl = "jdbc:derby://"
          + InetAddress.getLocalHost().getHostName() + ':' + this.netPort
          + "/newDB;create=true;";
      if (TestUtil.currentUserName != null) {
        derbyDbUrl += ("user=" + TestUtil.currentUserName + ";password="
            + TestUtil.currentUserPassword + ';');
      }
      derbyConn = DriverManager.getConnection(derbyDbUrl);
      // create schema
      derbyStmt = derbyConn.createStatement();

      startServerVMs(2, -1, "SG1");

      // create table
      serverSQLExecute(1,
          "create table TESTTABLE (ID int not null primary key , "
              + "DESCRIPTION varchar(1024) , ADDRESS varchar(1024), ID1 int ) "
              + "AsyncEventListener (WBCL2)  replicate ");

      tablesCreated = true;

      Runnable runnable = getExecutorForWBCLConfiguration("SG1", "WBCL2",
          "com.pivotal.gemfirexd.callbacks.DBSynchronizer",
          "org.apache.derby.jdbc.ClientDriver", derbyDbUrl, true,
          Integer.valueOf(1), null, Boolean.TRUE, null, null, null, 100000,
          "org.apache.derby.jdbc.ClientDriver," + derbyDbUrl, false);
      serverExecute(1, runnable);
      Runnable startWBCL = startAsyncEventListener("WBCL2");
      serverExecute(1, startWBCL);
      startClientVMs(1, 0, null);
      Connection conn = TestUtil.jdbcConn;
      String schema = ((EmbedConnection)TestUtil.jdbcConn)
          .getLanguageConnection().getCurrentSchemaName();
      if (schema == null) {
        schema = Misc.getDefaultSchemaName(((EmbedConnection)TestUtil.jdbcConn)
            .getLanguageConnection());
      }
      conn.createStatement();

      GfxdCallbacksTest.addLoader(schema, "TESTTABLE",
          "com.pivotal.gemfirexd.dbsync.DBSynchronizerTestBase$GfxdTestRowLoader",
          "");
      sqlExecuteVerify(new int[] { 1 }, null,
          "select ID from TESTTABLE where ID = 1", null, null);

      sqlExecuteVerify(new int[] { 1 }, null,
          "select ID from TESTTABLE where ID = 2", null, null);

      sqlExecuteVerify(new int[] { 1 }, null,
          "select ID from TESTTABLE where ID = 3", null, null);

      SerializableCallable queueChecker = getEmptyQueueChecker();
      Boolean retVal = (Boolean)serverExecute(1, queueChecker);
      assertTrue(retVal.booleanValue());

      retVal = (Boolean)serverExecute(2, queueChecker);
      assertTrue(retVal.booleanValue());

      ResultSet rs = derbyStmt.executeQuery("select * from testtable ");
      assertFalse(rs.next());

    } finally {
      ok = false;
      derbyStmt.executeUpdate("delete from testtable");
      cleanDerbyArtifacts(derbyStmt, new String[] {}, new String[] {},
          new String[] { "TESTTABLE" }, derbyConn);
      if (tablesCreated) {
        clientSQLExecute(1, "drop table TESTTABLE");
        // derbyStmt.execute("drop procedure validateTestEnd");
      }
      try {
        DriverManager.getConnection("jdbc:derby:;shutdown=true");
      } catch (SQLException sqle) {
        if (sqle.getMessage().indexOf("shutdown") == -1) {
          sqle.printStackTrace();
          throw sqle;
        }
      }
      if (server != null) {
        server.shutdown();
      }
    }
  }
 
Example 17
Source File: SerialDBSynchronizerPart2DUnit.java    From gemfirexd-oss with Apache License 2.0 4 votes vote down vote up
public void testTransactionalBehaviourOfAsyncEventListener_1()
    throws Exception {
  Connection derbyConn = null;
  Statement derbyStmt = null;
  NetworkServerControl server = null;
  try {
    server = startNetworkServer();
    createDerbyValidationArtefacts();
    String derbyDbUrl = "jdbc:derby://"
        + InetAddress.getLocalHost().getHostName() + ':' + this.netPort
        + "/newDB;create=true;";
    if (TestUtil.currentUserName != null) {
      derbyDbUrl += ("user=" + TestUtil.currentUserName + ";password="
          + TestUtil.currentUserPassword + ';');
    }
    derbyConn = DriverManager.getConnection(derbyDbUrl);
    // create schema
    derbyStmt = derbyConn.createStatement();
    // Create the controller VM as client which belongs to default server
    // group
    startClientVMs(1, 0, null);
    startServerVMs(1, -1, "SG1");
    // create table
    clientSQLExecute(1, "create table TESTTABLE (ID int not null "
        + "primary key, DESCRIPTION varchar(1024), ADDRESS varchar(1024), "
        + "ID1 int) AsyncEventListener (WBCL1)");

    Runnable runnable = getExecutorForWBCLConfiguration("SG1", "WBCL1",
        TXAsyncEventListener.class.getName(), null, derbyDbUrl, true,
        Integer.valueOf(1), null, Boolean.FALSE, null, null, null, 100000,
        null, false);
    runnable.run();
    Runnable startWBCL = startAsyncEventListener("WBCL1");
    clientExecute(1, startWBCL);
    Connection conn = TestUtil.jdbcConn;
    conn.setTransactionIsolation(Connection.TRANSACTION_READ_COMMITTED);
    conn.setAutoCommit(false);
    Statement stmt = conn.createStatement();
    // Do an insert in sql fabric. This will create a primary bucket on the
    // lone server VM with bucket ID =1

    stmt.executeUpdate("Insert into TESTTABLE values(114,'desc114','Add114',114)");

    stmt.executeUpdate("Insert into TESTTABLE values(1,'desc1','Add1',1)");
    stmt.executeUpdate("Insert into TESTTABLE values(227,'desc227','Add227',227)");
    stmt.executeUpdate("Insert into TESTTABLE values(340,'desc340','Add340',340)");
    conn.rollback();
    stmt.executeUpdate("Insert into TESTTABLE values(114,'desc114','Add114',114)");
    // Insert some more rows in gemfirexd
    stmt.executeUpdate("Insert into TESTTABLE values(1,'desc1','Add1',1)");
    stmt.executeUpdate("Insert into TESTTABLE values(2,'desc1','Add1',1)");
    stmt.executeUpdate("Insert into TESTTABLE values(224,'desc227','Add227',227)");
    stmt.executeUpdate("Insert into TESTTABLE values(331,'desc340','Add340',340)");
    conn.commit();
    // Bulk Update
    stmt.executeUpdate("update TESTTABLE set ID1 = ID1 +1 ");
    conn.rollback();
    // PK delete
    stmt.executeUpdate("delete from TESTTABLE where ID = " + DELETED_KEY);
    conn.commit();
    blockForValidation();
    stopAsyncEventListener("WBCL1").run();
    validateResults(derbyStmt, "select * from testtable", this.netPort, true);
  } finally {
    cleanDerbyArtifacts(derbyStmt, new String[] { "validateTestEnd" },
        new String[] { "test_ok" }, new String[] { "TESTTABLE" }, derbyConn);
    // might get ShutdownExceptions in derby connection close
    addExpectedDerbyException(ShutdownException.class.getName());
    try {
      DriverManager.getConnection("jdbc:derby:;shutdown=true");
    } catch (SQLException sqle) {
      if (sqle.getMessage().indexOf("shutdown") == -1) {
        sqle.printStackTrace();
        throw sqle;
      }
    }
    if (server != null) {
      server.shutdown();
    }
  }
}
 
Example 18
Source File: SerialDBSynchronizerPart2DUnit.java    From gemfirexd-oss with Apache License 2.0 4 votes vote down vote up
public void testTransactionalBehaviourOfDBSynchronizer_2() throws Exception {
  Connection derbyConn = null;
  Statement derbyStmt = null;
  NetworkServerControl server = null;
  try {
    server = startNetworkServer();
    createDerbyValidationArtefacts();
    String derbyDbUrl = "jdbc:derby://"
        + InetAddress.getLocalHost().getHostName() + ':' + this.netPort
        + "/newDB;create=true;";
    if (TestUtil.currentUserName != null) {
      derbyDbUrl += ("user=" + TestUtil.currentUserName + ";password="
          + TestUtil.currentUserPassword + ';');
    }
    derbyConn = DriverManager.getConnection(derbyDbUrl);
    // create schema
    derbyStmt = derbyConn.createStatement();
    // Create the controller VM as client which belongs to default server
    // group
    startVMs(1, 1, -1, "SG1", null);
    // create table
    clientSQLExecute(1, "create table TESTTABLE "
        + "(ID int not null primary key, DESCRIPTION varchar(1024), "
        + "ADDRESS varchar(1024), ID1 int) AsyncEventListener (WBCL1) ");

    Runnable runnable = getExecutorForWBCLConfiguration("SG1", "WBCL1",
        "com.pivotal.gemfirexd.callbacks.DBSynchronizer",
        "org.apache.derby.jdbc.ClientDriver", derbyDbUrl, true,
        Integer.valueOf(1), null, Boolean.FALSE, null, null, null, 100000,
        "org.apache.derby.jdbc.ClientDriver," + derbyDbUrl, false);
    runnable.run();
    Runnable startWBCL = startAsyncEventListener("WBCL1");
    clientExecute(1, startWBCL);
    Connection conn = TestUtil.jdbcConn;
    conn.setTransactionIsolation(Connection.TRANSACTION_READ_COMMITTED);
    conn.setAutoCommit(false);
    Statement stmt = conn.createStatement();
    PreparedStatement pstmt1 = conn
        .prepareStatement("insert into testtable values(?,?,?,?)");
    for (int i = 1; i < 10; ++i) {
      pstmt1.setInt(1, i);
      pstmt1.setString(2, "desc" + i);
      pstmt1.setString(3, "Add" + i);
      pstmt1.setInt(4, i);
      assertEquals(1, pstmt1.executeUpdate());
    }
    conn.commit();
    PreparedStatement pstmt2 = conn
        .prepareStatement("update testtable set ID1 = ? where description = ?");
    for (int i = 1; i < 5; ++i) {
      pstmt2.setInt(1, i * 10);
      pstmt2.setString(2, "desc" + i);
      assertEquals(1, pstmt2.executeUpdate());
    }
    conn.commit();
    PreparedStatement pstmt3 = conn
        .prepareStatement("select ID1 from TestTable where description = ?");
    for (int i = 1; i < 5; ++i) {
      pstmt3.setString(1, "desc" + i);
      ResultSet rs = pstmt3.executeQuery();
      assertTrue(rs.next());
      assertEquals(i * 10, rs.getInt(1));
    }
    // Now a delete a row & reinsert the row but with changed data . The
    // deletion should go via bulk op route
    assertEquals(1,
        stmt.executeUpdate("delete from TESTTABLE where ADDRESS = 'Add5'"));
    // Insert a row corresponding to the row deleted with Address as Add5
    pstmt1.setInt(1, 5);
    pstmt1.setString(2, "desc.5");
    pstmt1.setString(3, "Add5");
    pstmt1.setInt(4, 5);
    assertEquals(1, pstmt1.executeUpdate());
    conn.commit();
    // PK delete
    stmt.executeUpdate("delete from TESTTABLE where ID = " + DELETED_KEY);
    conn.commit();
    blockForValidation();
    stopAsyncEventListener("WBCL1").run();
    validateResults(derbyStmt, "select * from testtable", this.netPort, true);
  } finally {
    cleanDerbyArtifacts(derbyStmt, new String[] { "validateTestEnd" },
        new String[] { "test_ok" }, new String[] { "TESTTABLE" }, derbyConn);
    // might get ShutdownExceptions in derby connection close
    addExpectedDerbyException(ShutdownException.class.getName());
    try {
      DriverManager.getConnection("jdbc:derby:;shutdown=true");
    } catch (SQLException sqle) {
      if (sqle.getMessage().indexOf("shutdown") == -1) {
        sqle.printStackTrace();
        throw sqle;
      }
    }
    if (server != null) {
      server.shutdown();
    }
  }
}
 
Example 19
Source File: SerialDBSynchronizerPart2DUnit.java    From gemfirexd-oss with Apache License 2.0 4 votes vote down vote up
public void testDBSynchronizerAfterTruncateTable_Partition() throws Exception {
  Connection derbyConn = null;
  Statement derbyStmt = null;
  NetworkServerControl server = null;
  try {
    server = startNetworkServer();
    createDerbyValidationArtefacts();
    String derbyDbUrl = "jdbc:derby://"
        + InetAddress.getLocalHost().getHostName() + ':' + this.netPort
        + "/newDB;create=true;";
    if (TestUtil.currentUserName != null) {
      derbyDbUrl += ("user=" + TestUtil.currentUserName + ";password="
          + TestUtil.currentUserPassword + ';');
    }
    derbyConn = DriverManager.getConnection(derbyDbUrl);
    // create schema
    derbyStmt = derbyConn.createStatement();

    // Create the controller VM as client which belongs to default server
    // group
    startClientVMs(1, 0, null);
    startServerVMs(1, -1, "SG1");
    // create table
    clientSQLExecute(1,
        "create table TESTTABLE (ID int not null primary key , "
            + "DESCRIPTION varchar(1024) , ADDRESS varchar(1024), ID1 int )"
            + " partition by primary key AsyncEventListener (WBCL1) ");

    Runnable runnable = getExecutorForWBCLConfiguration("SG1", "WBCL1",
        "com.pivotal.gemfirexd.callbacks.DBSynchronizer",
        "org.apache.derby.jdbc.ClientDriver", derbyDbUrl, true,
        Integer.valueOf(1), null, Boolean.FALSE, null, null, null, 100000,
        "org.apache.derby.jdbc.ClientDriver," + derbyDbUrl, false);
    runnable.run();
    Runnable startWBCL = startAsyncEventListener("WBCL1");
    clientExecute(1, startWBCL);
    Connection conn = TestUtil.jdbcConn;
    conn.setTransactionIsolation(Connection.TRANSACTION_READ_COMMITTED);
    Statement stmt = conn.createStatement();
    // Do an insert in sql fabric. This will create a primary bucket on the
    // lone server VM
    // with bucket ID =1

    stmt.executeUpdate("Insert into TESTTABLE values(1114,'desc114','Add114',114)");
    stmt.executeUpdate("Insert into TESTTABLE values(11,'desc1','Add1',1)");
    stmt.executeUpdate("Insert into TESTTABLE values(1227,'desc227','Add227',227)");
    stmt.executeUpdate("Insert into TESTTABLE values(1340,'desc340','Add340',340)");
    conn.commit();

    stmt.executeUpdate("truncate table TESTTABLE");
    conn.commit();
    // assert empty table
    ResultSet rs = stmt.executeQuery("select count(*) from TESTTABLE");
    JDBC.assertSingleValueResultSet(rs, "0");

    // delete everything in GemFireXD again, because truncate table as DDL won't
    // be propagated to Derby
    // However, the following delete as DML will be propagated to Derby to do
    // something equivalent to truncate table
    stmt.executeUpdate("delete from TESTTABLE");

    // Insert some more rows in gemfirexd
    stmt.executeUpdate("Insert into TESTTABLE values(114,'desc114','Add114',114)");
    stmt.executeUpdate("Insert into TESTTABLE values(1,'desc1','Add1',1)");
    stmt.executeUpdate("Insert into TESTTABLE values(2,'desc1','Add1',1)");
    stmt.executeUpdate("Insert into TESTTABLE values(224,'desc227','Add227',227)");
    stmt.executeUpdate("Insert into TESTTABLE values(331,'desc340','Add340',340)");
    conn.commit();
    // Bulk Update
    stmt.executeUpdate("update TESTTABLE set ID1 = ID1 +1 ");
    conn.rollback();
    // PK delete
    stmt.executeUpdate("delete from TESTTABLE where ID = " + DELETED_KEY);
    conn.commit();

    blockForValidation();
    stopAsyncEventListener("WBCL1").run();
    validateResults(derbyStmt, "select * from testtable", this.netPort, true);
  } finally {
    cleanDerbyArtifacts(derbyStmt, new String[] { "validateTestEnd" },
        new String[] { "test_ok" }, new String[] { "TESTTABLE" }, derbyConn);
    // might get ShutdownExceptions in derby connection close
    addExpectedDerbyException(ShutdownException.class.getName());
    try {
      DriverManager.getConnection("jdbc:derby:;shutdown=true");
    } catch (SQLException sqle) {
      if (sqle.getMessage().indexOf("shutdown") == -1) {
        sqle.printStackTrace();
        throw sqle;
      }
    }
    if (server != null) {
      server.shutdown();
    }
  }
}
 
Example 20
Source File: SerialDBSynchronizerPart1DUnit.java    From gemfirexd-oss with Apache License 2.0 4 votes vote down vote up
public void testDBSynchronizerPRWithSynchronizerOnNonRedundantDataStoreAndDMLOnAccessor()
    throws Exception {
  Statement derbyStmt = null;
  Connection derbyConn = null;
  NetworkServerControl server = null;
  try {
    String derbyDbUrl = "jdbc:derby://"
        + InetAddress.getLocalHost().getHostName() + ':' + this.netPort
        + "/newDB;create=true;";
    if (TestUtil.currentUserName != null) {
      derbyDbUrl += ("user=" + TestUtil.currentUserName + ";password="
          + TestUtil.currentUserPassword + ';');
    }
    server = startNetworkServer();
    createDerbyValidationArtefacts();
    derbyConn = DriverManager.getConnection(derbyDbUrl);
    // create schema
    derbyStmt = derbyConn.createStatement();
    // Create the controller VM as client which belongs to default server
    // group
    startClientVMs(1, 0, null);
    startServerVMs(3, -1, "SG1");
    // create table
    clientSQLExecute(1,
        "create table TESTTABLE (ID int not null primary key, "
            + "DESCRIPTION varchar(1024) , ADDRESS varchar(1024), ID1 int) server groups(SG1) redundancy 1");
           // + "AsyncEventListener (WBCL1)");

    clientSQLExecute(1, "alter table TESTTABLE set AsyncEventListener (WBCL1)");

    Runnable runnable = getExecutorForWBCLConfiguration("SG1", "WBCL1",
        "com.pivotal.gemfirexd.callbacks.DBSynchronizer",
        "org.apache.derby.jdbc.ClientDriver", derbyDbUrl + ",app,app", true,
        Integer.valueOf(1), null, Boolean.FALSE, null, null, null, 100000, "", false);
    runnable.run();
    Runnable startWBCL = startAsyncEventListener("WBCL1");
    clientExecute(1, startWBCL);
    pause(5000);
    // Do an insert in sql fabric
    clientSQLExecute(1, "Insert into TESTTABLE values(1,'desc1','Add1',1)");
    clientSQLExecute(1, "Insert into TESTTABLE values(2,'desc2','Add2',2)");
    clientSQLExecute(1, "Insert into TESTTABLE values(3,'desc3','Add3',3)");
    clientSQLExecute(1, "Insert into TESTTABLE values(4,'desc4','Add4',4)");
    clientSQLExecute(1, "Insert into TESTTABLE values(5,'desc5','Add5',5)");
    clientSQLExecute(1, "Insert into TESTTABLE values(6,'desc6','Add6',6)");
    // Bulk Update
    clientSQLExecute(1, "update TESTTABLE set ID1 = ID1 +1 ");

    // Bulk Delete
    clientSQLExecute(1, "delete from testtable where ADDRESS = 'Add5'");
    clientSQLExecute(1, "delete from TESTTABLE where ID = " + DELETED_KEY);
    blockForValidation();
    stopAsyncEventListener("WBCL1").run();
    Thread.sleep(5000);
    validateResults(derbyStmt, "select * from testtable", this.netPort, true);
  }
  finally {
    cleanDerbyArtifacts(derbyStmt, new String[] {}, new String[] {},
        new String[] { "TESTTABLE" }, derbyConn);
    // might get ShutdownExceptions in derby connection close
    addExpectedDerbyException(ShutdownException.class.getName());
    try {
      DriverManager.getConnection("jdbc:derby:;shutdown=true");
    }
    catch (SQLException sqle) {
      if (sqle.getMessage().indexOf("shutdown") == -1) {
        sqle.printStackTrace();
        throw sqle;
      }
    }
    if (server != null) {
      server.shutdown();
    }
  }
}