Package org.voltdb.client

Examples of org.voltdb.client.ClientResponse


        CatalogContext catalogContext = this.getCatalogContext();
        Client client = this.getClient();
        TestSmallBankSuite.initializeSmallBankDatabase(catalogContext, client);
        long acctIds[] = { 1l, 2l };
        double balances[] = { 100d, 0d };
        ClientResponse cresponse;
        VoltTable results[];

        Table catalog_tbl = catalogContext.getTableByName(SmallBankConstants.TABLENAME_ACCOUNTS);
        long num_rows = RegressionSuiteUtil.getRowCount(client, catalog_tbl);
        assert(num_rows > acctIds[acctIds.length-1]);
        // System.err.println("# of Rows: " + num_rows);
       
        for (int i = 0; i < acctIds.length; i++) {
            updateBalance(client, acctIds[i], balances[i]);
            checkBalance(client, acctIds[i], balances[i]);
        } // FOR
       
        // Run the SendPayment txn to send all the money from the first
        // account to the second account.
        cresponse = client.callProcedure(SendPayment.class.getSimpleName(),
                                         acctIds[0], acctIds[1], balances[0]);
        assertEquals(Status.OK, cresponse.getStatus());
        results = cresponse.getResults();
        assertEquals(2, results.length);
        for (int i = 0; i < results.length; i++) {
            assertEquals(1l, results[i].asScalarLong());
            // System.err.println(VoltTableUtil.format(results[i]));
        } // FOR
View Full Code Here


        Client client = this.getClient();
        TestSmallBankSuite.initializeSmallBankDatabase(catalogContext, client);
       
        long acctIds[] = { 1l, 2l };
        double balances[] = { 0d, 100d };
        ClientResponse cresponse;
       
        for (int i = 0; i < acctIds.length; i++) {
            updateBalance(client, acctIds[i], balances[i]);
            checkBalance(client, acctIds[i], balances[i]);
        } // FOR
       
        // Run the SendPayment txn that tries to send to money from the first account,
        // but it should fail because the balance is zero
        try {
            cresponse = client.callProcedure(SendPayment.class.getSimpleName(),
                                             acctIds[0], acctIds[1], balances[1]);
        } catch (ProcCallException ex) {
            cresponse = ex.getClientResponse();
        }
        assertEquals(Status.ABORT_USER, cresponse.getStatus());
       
        // Make sure the account balances are still the same
        for (int i = 0; i < acctIds.length; i++) {
            checkBalance(client, acctIds[i], balances[i]);
        } // FOR
View Full Code Here

    public static void checkBalance(Client client, long acctId, double expected) throws Exception {
        // Make sure that we set it correctly
        String query = String.format("SELECT * FROM %s WHERE custid = %d",
                              SmallBankConstants.TABLENAME_CHECKING, acctId);
        ClientResponse cresponse = client.callProcedure("@AdHoc", query);
        assertEquals(Status.OK, cresponse.getStatus());
        VoltTable results[] = cresponse.getResults();
        assertEquals(1, results.length);
       
        if (results[0].getRowCount() == 0) {
            System.err.println(VoltTableUtil.format(results[0]));
        }
View Full Code Here

        // Prime the customer's balance
        String query = String.format("UPDATE %s SET bal = %f WHERE custid = %d",
                                     SmallBankConstants.TABLENAME_CHECKING,
                                     balance, acctId);
        String procName = VoltSystemProcedure.procCallName(AdHoc.class);
        ClientResponse cresponse = client.callProcedure(procName, query);
        assertEquals(Status.OK, cresponse.getStatus());
        VoltTable results[] = cresponse.getResults();
        assertEquals(1, results.length);
        assertTrue(results[0].advanceRow());
    }
View Full Code Here

    public void testAppStatus() throws Exception {
        System.out.println("STARTING testAppStatus");
        Client client = getClient();

        ClientResponse response = client.callProcedure( "ReturnAppStatus", 0, "statusstring", (byte)0);
        assertNull(response.getAppStatusString());
        assertEquals(response.getAppStatus(), Byte.MIN_VALUE);
        assertEquals(response.getResults()[0].getStatusCode(), Byte.MIN_VALUE);

        response = client.callProcedure( "ReturnAppStatus", 1, "statusstring", (byte)1);
        assertTrue(response.getAppStatusString(), "statusstring".equals(response.getAppStatusString()));
        assertEquals(response.getAppStatus(), 1);
        assertEquals(response.getResults()[0].getStatusCode(), 1);

        response = client.callProcedure( "ReturnAppStatus", 2, "statusstring", (byte)2);
        assertNull(response.getAppStatusString(), response.getAppStatusString());
        assertEquals(response.getAppStatus(), 2);
        assertEquals(response.getResults()[0].getStatusCode(), 2);

        response = client.callProcedure( "ReturnAppStatus", 3, "statusstring", (byte)3);
        assertTrue(response.getAppStatusString(), "statusstring".equals(response.getAppStatusString()));
        assertEquals(response.getAppStatus(), Byte.MIN_VALUE);
        assertEquals(response.getResults()[0].getStatusCode(), 3);

        boolean threwException = false;
        try {
            response = client.callProcedure( "ReturnAppStatus", 4, "statusstring", (byte)4);
        } catch (ProcCallException e) {
            threwException = true;
            response = e.getClientResponse();
        }
        assertTrue(threwException);
        assertTrue("statusstring".equals(response.getAppStatusString()));
        assertEquals(response.getAppStatus(), 4);
    }
View Full Code Here

        // Wait until we have both latches
        dtxnCallback.latch.await(sleepTime*2, TimeUnit.MILLISECONDS);
        spCallback.latch.await(sleepTime*2, TimeUnit.MILLISECONDS);
       
        // Then verify the DTXN results
        ClientResponse dtxnResponse = CollectionUtil.first(dtxnCallback.responses);
        assertNotNull(dtxnResponse);
        assertEquals(Status.OK, dtxnResponse.getStatus());
        assertTrue(dtxnResponse.hasDebug());
        assertFalse(dtxnResponse.isSinglePartition());
        assertFalse(dtxnResponse.isSpeculative());
       
        // And the SP results. Where is your god now?
        ClientResponse spResponse = CollectionUtil.first(spCallback.responses);
        assertNotNull(spResponse);
        assertEquals(Status.OK, spResponse.getStatus());
        assertTrue(spResponse.hasDebug());
        assertTrue(spResponse.isSinglePartition());
       
        // There is currently a race condition for whether the txn will get
        // speculatively executed or not, so for now we'll just disable this
        // one check.
        // sassertTrue(spResponse.isSpeculative());
       
        // SANITY CHECK
        // We should have exaclty two different MSC_LOCATION values
        String procName = VoltSystemProcedure.procCallName(AdHoc.class);
        String query = "SELECT COUNT(DISTINCT MSC_LOCATION) FROM " + TM1Constants.TABLENAME_SUBSCRIBER;
        ClientResponse cresponse = client.callProcedure(procName, query);
        assertEquals(Status.OK, cresponse.getStatus());
        assertEquals(2, cresponse.getResults()[0].asScalarLong());
        System.err.println(cresponse);
    }
View Full Code Here

    public void testRemoteIdle() throws Exception {
        Client client = this.getClient();
        RegressionSuiteUtil.initializeTM1Database(this.getCatalogContext(), client);
       
        final int sleepTime = 10000; // ms
        final ClientResponse dtxnResponse[] = new ClientResponse[1];
        final AtomicBoolean latch = new AtomicBoolean(true);
        final ProcedureCallback callback = new ProcedureCallback() {
            @Override
            public void clientCallback(ClientResponse clientResponse) {
                // System.err.println("DISTRUBTED RESULT " + clientResponse);
                dtxnResponse[0] = clientResponse;
                latch.set(false);
            }
        };
       
        // We're going to first execute a long running and slow distributed transaction
        // on the first partition. It will sleep for 10 seconds
        String procName = RemoteIdle.class.getSimpleName();
        Object params[] = { 0, sleepTime };
        client.callProcedure(callback, procName, params);
        long start = System.currentTimeMillis();
       
        // While we're waiting for that to come back, we're going to fire off
        // a bunch of single-partition txns that should all be executed
        // speculatively at the other partition
        TM1Client.Transaction txn = Transaction.GET_SUBSCRIBER_DATA;
        params = new Object[]{ 1 };
        ClientResponse cresponse = null;
        int specexec_ctr = 0;
        while (latch.get()) {
            // Just sleep for a little bit so that we don't blast the cluster
            ThreadUtil.sleep(500);
           
            // System.err.println("Requesting " + txn + " for speculative execution");
            try {
                cresponse = client.callProcedure(txn.callName, params);
                assertEquals(Status.OK, cresponse.getStatus());
            } catch (ProcCallException ex) {
                cresponse = ex.getClientResponse();
                assertEquals(cresponse.toString(), Status.ABORT_USER, cresponse.getStatus());
            }
            // System.err.println(cresponse.toString());
            // System.err.println();
           
            // We'll only check the txns half way through the dtxns expected
            // sleep time
            long elapsed = System.currentTimeMillis() - start;
            assert(elapsed <= sleepTime*1.25);
            if (elapsed < sleepTime/2) {
                assertEquals(cresponse.toString(), latch.get(), cresponse.isSpeculative());
                System.err.println(cresponse.getDebug());
            }
            if (cresponse.isSpeculative()) specexec_ctr++;
        } // WHILE
        assert(specexec_ctr > 0);

        cresponse = dtxnResponse[0];
        assertNotNull(cresponse);
        assertTrue(cresponse.hasDebug());
        assertFalse(cresponse.isSinglePartition());
        assertFalse(cresponse.isSpeculative());
    }
View Full Code Here

    public void testUpdateSubscriberData() throws Exception {
        Client client = this.getClient();
        RegressionSuiteUtil.initializeTM1Database(this.getCatalogContext(), client);
        TM1Client.Transaction txn = Transaction.UPDATE_SUBSCRIBER_DATA;
        Object params[] = txn.generateParams(NUM_SUBSCRIBERS);
        ClientResponse cresponse = null;
        try {
            cresponse = client.callProcedure(txn.callName, params);
            assertEquals(Status.OK, cresponse.getStatus());
        } catch (ProcCallException ex) {
            cresponse = ex.getClientResponse();
            assertEquals(Status.ABORT_USER, cresponse.getStatus());
        }
        assertNotNull(cresponse);
        assertTrue(cresponse.toString(), cresponse.isSinglePartition());
    }
View Full Code Here

            e.printStackTrace();
            fail();
        }

        try {
            ClientResponse cr = client.callProcedure("SelectAll");
            VoltTable[] results = cr.getResults();

            assertEquals(results.length, 9);

            // get the new order table
            VoltTable table = results[6];
            assertEquals(cr.toString(), 0, table.getRowCount());

            // check the mat view
            cr = client.callProcedure("ReadMatView", 2);
            results = cr.getResults();
            assertEquals(cr.toString(), 1, results.length);
            assertEquals(cr.toString(), 0, results[0].getRowCount());
        }
        catch (ProcCallException e) {
            e.printStackTrace();
            fail();
        }
View Full Code Here

        }

        try {
            System.out.println("Calling SelectAll");
            System.out.flush();
            ClientResponse cr = client.callProcedure("SelectAll");
            System.err.println(cr);
            VoltTable[] results = cr.getResults();
            System.out.println("Called SelectAll");
            System.out.flush();

            assertEquals(results.length, 9);

            // get the new order table
            VoltTable table = results[2];
            System.out.println(table.toString());
            assertEquals(cr.toString(), 0, table.getRowCount());

        }
        catch (ProcCallException e) {
            e.printStackTrace();
            fail();
View Full Code Here

TOP

Related Classes of org.voltdb.client.ClientResponse

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.