Beispiel #1
0
  private final ClientResponse callProcedure(
      SyncCallback cb, long nowNanos, long timeout, ProcedureInvocation invocation)
      throws IOException, NoConnectionsException, ProcCallException {
    if (m_isShutdown) {
      throw new NoConnectionsException("Client instance is shutdown");
    }

    if (m_blessedThreadIds.contains(Thread.currentThread().getId())) {
      throw new IOException(
          "Can't invoke a procedure synchronously from with the client callback thread "
              + " without deadlocking the client library");
    }

    m_distributer.queue(invocation, cb, true, nowNanos, timeout);

    try {
      cb.waitForResponse();
    } catch (final InterruptedException e) {
      throw new java.io.InterruptedIOException("Interrupted while waiting for response");
    }
    if (cb.getResponse().getStatus() != ClientResponse.SUCCESS) {
      throw new ProcCallException(cb.getResponse(), cb.getResponse().getStatusString(), null);
    }
    // cb.result() throws ProcCallException if procedure failed
    return cb.getResponse();
  }
  /**
   * add 20 shuffled rows
   *
   * @throws InterruptedException
   */
  private void load(Client client)
      throws NoConnectionsException, ProcCallException, IOException, InterruptedException {
    int pkey = 0;
    a_int.clear();
    a_inline_str.clear();
    a_pool_str.clear();

    boolean async = true;

    for (int i = 0; i < 20; i++) {
      a_int.add(i);
      a_inline_str.add("a_" + i);
      a_pool_str.add(simpleString + i);
    }

    Collections.shuffle(a_int);
    Collections.shuffle(a_inline_str);
    Collections.shuffle(a_pool_str);

    for (int i = 0; i < 20; i++) {
      SyncCallback cb = new SyncCallback();
      client.callProcedure(
          cb, "InsertO1", pkey, a_int.get(i), a_inline_str.get(i), a_pool_str.get(i));

      if (!async) {
        cb.waitForResponse();
        VoltTable vt = cb.getResponse().getResults()[0];
        assertTrue(vt.getRowCount() == 1);
      }
      pkey = pkey + 1;
    }

    client.drain();
  }
  public void testRejoinSysprocButFail() throws Exception {
    VoltProjectBuilder builder = getBuilderForTest();
    boolean success = builder.compile(Configuration.getPathToCatalogForTest("rejoin.jar"), 1, 1, 0);
    assertTrue(success);
    MiscUtils.copyFile(
        builder.getPathToDeployment(), Configuration.getPathToCatalogForTest("rejoin.xml"));

    VoltDB.Configuration config = new VoltDB.Configuration();
    config.m_pathToCatalog = Configuration.getPathToCatalogForTest("rejoin.jar");
    config.m_pathToDeployment = Configuration.getPathToCatalogForTest("rejoin.xml");
    config.m_isRejoinTest = true;
    ServerThread localServer = new ServerThread(config);

    localServer.start();
    localServer.waitForInitialization();

    Client client = ClientFactory.createClient();
    client.createConnection("localhost");

    SyncCallback scb = new SyncCallback();
    success = false;
    while (!success) {
      success = client.callProcedure(scb, "@Rejoin", "localhost", config.m_internalPort + 1);
      if (!success) Thread.sleep(100);
    }

    scb.waitForResponse();
    ClientResponse response = scb.getResponse();
    assertTrue(response.getStatusString().contains("Unable to find down node"));

    client.close();
    localServer.shutdown();
    localServer.join();
  }
  private static void load(Client client)
      throws NoConnectionsException, IOException, InterruptedException {
    for (int i = 0; i < 10; i++) {
      SyncCallback cb = new SyncCallback();
      client.callProcedure(cb, "InsertA", i, i);
      cb.waitForResponse();
      assertEquals(1, cb.getResponse().getResults()[0].asScalarLong());
    }

    for (int i = 0; i < 10; i++) {
      SyncCallback cb = new SyncCallback();
      client.callProcedure(cb, "InsertB", i, i);
      cb.waitForResponse();
      assertEquals(1, cb.getResponse().getResults()[0].asScalarLong());
    }
  }
  boolean failNext(int failType) throws Exception {
    Context context = getServerReadyToReceiveNewNode();

    Client client = ClientFactory.createClient();
    client.createConnection("localhost");

    ServerSocketChannel listener = null;
    if (failType != FAIL_NO_OPEN_SOCKET) {
      try {
        listener = ServerSocketChannel.open();
        listener.socket().bind(new InetSocketAddress(VoltDB.DEFAULT_INTERNAL_PORT + 1));
      } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
        System.exit(-1);
      }
    }

    SyncCallback scb = new SyncCallback();
    boolean success = false;
    while (!success) {
      success = client.callProcedure(scb, "@Rejoin", "localhost", VoltDB.DEFAULT_INTERNAL_PORT + 1);
      if (!success) Thread.sleep(100);
    }

    SocketChannel socket = null;
    if (failType != FAIL_NO_OPEN_SOCKET) {
      socket = listener.accept();
      listener.close();
      DataOutputStream out =
          new DataOutputStream(new BufferedOutputStream(socket.socket().getOutputStream()));
      DataInputStream in =
          new DataInputStream(new BufferedInputStream(socket.socket().getInputStream()));

      int hostId = in.readInt();
      assertEquals(hostId, 1);

      if (failType != FAIL_TIMEOUT_ON_SOCKET) {
        // COMMAND_SENDTIME_AND_CRC
        out.writeInt(4);
        out.flush();
        // ignore what the other host says the time is
        in.readLong();
        // fake a clock skew of 1ms
        if (failType == FAIL_SKEW) {
          out.writeLong(100000);
          // COMMAND_NTPFAIL
          out.writeInt(5);
        } else {
          out.writeLong(1);
          // COMMAND_COMPLETE
          out.writeInt(3);
        }
        out.flush();
      }
    }

    scb.waitForResponse();
    ClientResponse response = scb.getResponse();

    switch (failType) {
      case FAIL_NO_OPEN_SOCKET:
        assertTrue(response.getStatus() != ClientResponse.SUCCESS);
        break;
      case FAIL_TIMEOUT_ON_SOCKET:
        assertTrue(response.getStatus() != ClientResponse.SUCCESS);
        break;
      case FAIL_SKEW:
        assertTrue(response.getStatus() != ClientResponse.SUCCESS);
        break;
      case DONT_FAIL:
        assertTrue(response.getStatus() == ClientResponse.SUCCESS);
        break;
    }

    if (failType != FAIL_NO_OPEN_SOCKET) socket.close();
    context.localServer.shutdown();
    context.localServer.join();

    client.close();

    Thread.sleep(250);
    // this means there is nothing else to try
    return failType != DONT_FAIL;
  }