Package org.voltdb.client

Examples of org.voltdb.client.Client


    /**
     * testConcurrentTxns
     */
    public void testConcurrentTxns() throws Exception {
        Client client = this.getClient();
        this.initializeDatabase(client);
       
        final int num_txns = 500;
        final CountDownLatch latch = new CountDownLatch(num_txns);
        final AtomicInteger numTotal = new AtomicInteger(0);
        final AtomicInteger numCompleted = new AtomicInteger(0);
        final AtomicInteger numFailed = new AtomicInteger(0);
       
        ProcedureCallback callback = new ProcedureCallback() {
            @Override
            public void clientCallback(ClientResponse cr) {
                switch (cr.getStatus()) {
                    case OK:
                        if (cr.getResults()[0].asScalarLong() == VoterConstants.VOTE_SUCCESSFUL) {
                            numCompleted.incrementAndGet();
                        }
                        break;
                    default:
                        numFailed.incrementAndGet();
                        System.err.printf("UNEXPECTED: %s [%d]\n", cr.getStatus(), numFailed.get());
                } // SWITCH
                numTotal.incrementAndGet();
                latch.countDown();
            }
        };
       
        for (int i = 0; i < num_txns; i++) {
            Object params[] = {
                new Long(i),
                PHONE_NUMBER + (i % 10),
                i % VoterConstants.NUM_CONTESTANTS,
                MAX_VOTES_PER_PHONE_NUMBER
            };
            client.callProcedure(callback, Vote.class.getSimpleName(), params);
        } // FOR
        System.err.printf("Invoked %d txns. Waiting for responses...\n", num_txns);
        boolean result = latch.await(15, TimeUnit.SECONDS);
        System.err.println("LATCH RESULT: " + result);
        System.err.println("TOTAL:        " + numTotal.get() + " / " + num_txns);
        System.err.println("COMPLETED:    " + numCompleted.get());
        System.err.println("FAILED:       " + numFailed.get());
        if (result == false) {
            System.err.println("BAD MOJO");
        }
       
        assertTrue("Timed out [latch="+latch.getCount() + "]", result);
        assertEquals(0, numFailed.get());
       
        // At this point we know that all of our txns have been committed to disk
        // Make sure that our vote is actually in the real table and materialized views
        String query = "SELECT COUNT(*) FROM votes";
        ClientResponse cresponse = client.callProcedure("@AdHoc", query);
        System.err.println(cresponse);
        assertEquals(Status.OK, cresponse.getStatus());
        VoltTable results[] = cresponse.getResults();
        assertEquals(1, results.length);
        assertEquals(numCompleted.get(), results[0].asScalarLong());
View Full Code Here


    }
   
    @Test
    public void testMMRquery1 () throws IOException, ProcCallException {
        //int num_partitions = this.getServerConfig().getPartitionCount();
        Client client = this.getClient();
        final VoltTable vt = this.loadTable_ORDER_LINE(client);
       
        assertEquals(vt.getColumnCount(), 10);
       
        // Computer Query1 information
        /* MapReduce OLAP Experimental Queries
        addStmtProcedure("OLAPQuery1",
                         "SELECT ol_number, SUM(ol_quantity), SUM(ol_amount), " +
                         "       AVG(ol_quantity), AVG(ol_amount), COUNT(*)" +
                         "  FROM ORDER_LINE " +
                         " GROUP BY ol_number order by ol_number");*/
       
        // 0:ol_number,1:sum(ol_quantity),2:SUM(ol_amount),3:weight(ol_quantity),4:weight(ol_amount),5:sum
        List< List<Object>> rtLists = new ArrayList< List< Object >>();
        vt.resetRowPosition();
        Map<Integer,Integer> map = new HashMap<Integer,Integer>();
        //Set <Integer> keyset = new HashSet <Integer>();
        Integer ct = 0;
        while(vt.advanceRow()) {
            Integer key = new Integer ((int) vt.getLong(3));
            if (!map.containsKey(key)) {
                map.put(new Integer ((int) vt.getLong(3)),ct);
                List <Object> cont = new ArrayList<Object>();
                rtLists.add(ct,cont);
               
                cont.add(0,key);
                //rtLists.get(ct).add(0, vt.getLong(3));
                if (cont.size() < 2) cont.add(1, vt.getLong(7));
                else cont.set(1, vt.getLong(7) + ((Long)cont.get(1)).longValue());
                if (cont.size() < 3) cont.add(2, vt.getDouble(8));
                else cont.set(2, vt.getDouble(8) + ((Double)cont.get(2)).doubleValue());
                if (cont.size() < 4) cont.add(3, 1);
                else cont.set(3, ((Integer)cont.get(3)).intValue() + 1);
               
                ct++;
            } else {
                int index = map.get(key);
                assertEquals(key, rtLists.get(index).get(0));
                //rtLists.get(ct).set(0, vt.getLong(3));
                rtLists.get(index).set(1, vt.getLong(7) + ((Long)rtLists.get(index).get(1)).longValue());
                rtLists.get(index).set(2, vt.getDouble(8) + ((Double)rtLists.get(index).get(2)).doubleValue());
                rtLists.get(index).set(3, ((Integer)rtLists.get(index).get(3) ).intValue()+ 1);
            }
        }
       
        // execute MapReduce Transaction to check the result
        ClientResponse cr = client.callProcedure("MRquery1");
        assertEquals(Status.OK, cr.getStatus());
        System.out.println("I am starting to compare the results...");
        int index = -1;
        // 0:ol_number,1:sum(ol_quantity),2:SUM(ol_amount),3:weight(ol_quantity),4:weight(ol_amount),5:sum
        for ( VoltTable v : cr.getResults()) {
View Full Code Here

    public void testUpdateDecimalWithPVE()
    throws NoConnectionsException, ProcCallException, IOException
    {
        // insert a couple of rows.
        final Client client = this.getClient();
        final Object params[] = new Object[COLS + 2];
        params[0] = "ALLOW_NULLS";
        params[1] = 0;
        for (int i=0; i < COLS; i++) {
            params[i+2] = m_midValues[i];
        }
        client.callProcedure("Insert", params);

        // insert one row with the max values
        params[0] = "ALLOW_NULLS";
        params[1] = 1;
        for (int i=0; i < COLS; i++) {
            params[i+2] = m_maxValues[i];
        }
        client.callProcedure("Insert", params);

        // update the mid value to the minimum decimal value
        VoltTable[] result = client.callProcedure("UpdateDecimal", m_minValues[10], m_midValues[10]).getResults();

        // select that same row again by primary key
        result = client.callProcedure("Select", "ALLOW_NULLS", 0).getResults();

        // and verify the row
        final VoltTableRow row = result[0].fetchRow(0);
        final BigDecimal bd = (row.getDecimalAsBigDecimal(11));
        assertTrue(comparisonHelper(m_minValues[10], bd, m_types[10]));
View Full Code Here

    }

    public void testInvalidParameterSerializations()
    throws NoConnectionsException, ProcCallException, IOException
    {
        final Client client = this.getClient();
        final Object params[] = new Object[8];

        params[0] = new short[1];
        params[1] = new int[1];
        params[2] = new long[1];
        params[3] = new double[1];
        params[4] = new String[1];
        params[5] = new TimestampType[1];
        params[6] = new BigDecimal[1];
        params[7] = new byte[1];

        // make sure the procedure CAN work.
        client.callProcedure("ParamSetArrays", params);

        // now cycle through invalid array lengths
        // these should fail in client serialization to the server
        params[0] = new short[Short.MAX_VALUE + 1];
        helper_testInvalidParameterSerializations(client, params);
View Full Code Here

    public TestMaterializedViewSuite(String name) {
        super(name);
    }

    public void testInsertSinglePartition() throws IOException, ProcCallException {
        Client client = getClient();
        VoltTable[] results = null;

        results = client.callProcedure("AggAges", 1L).getResults();
        assertEquals(1, results.length);
        assertEquals(0, results[0].getRowCount());
        assert(results != null);
       
        results = client.callProcedure("AddPerson", 1L, 1L, 31L, 27500.20, 7).getResults();
        assertEquals(1, results.length);
        results = client.callProcedure("AddPerson", 1L, 2L, 31L, 28920.99, 3).getResults();
        assertEquals(1, results.length);
        results = client.callProcedure("AddPerson", 1L, 3L, 32L, 63250.01, -1).getResults();
        assertEquals(1, results.length);

        results = client.callProcedure("AggAges", 1L).getResults();
        assertEquals(1, results.length);
        assertEquals(2, results[0].getRowCount());
        assert(results != null);
    }
View Full Code Here

        assertEquals(2, results[0].getRowCount());
        assert(results != null);
    }

    public void testDeleteSinglePartition() throws IOException, ProcCallException {
        Client client = getClient();
        VoltTable[] results = null;
       
        /*

        results = client.callProcedure("AggAges", 1L).getResults();
View Full Code Here

        assert(results != null);
         */
    }

    public void testUpdateSinglePartition() throws IOException, ProcCallException {
        Client client = getClient();
        VoltTable[] results = null;
       
        /*

        results = client.callProcedure("AggAges", 1L).getResults();
View Full Code Here

        assertEquals(3L, r2.getLong(3));
         */
    }

    public void testSinglePartitionWithPredicates() throws IOException, ProcCallException {
        Client client = getClient();
        VoltTable[] results = null;
       
        /*

        results = client.callProcedure("AggAges", 1L).getResults();
View Full Code Here

        
         */
    }

    public void testMultiPartitionSimple() throws IOException, ProcCallException {
        Client client = getClient();
        VoltTable[] results = null;
       
        /*

        results = client.callProcedure("AggAges", 1L).getResults();
View Full Code Here

        
         */
    }

    public void testInsertReplicated() throws IOException, ProcCallException {
        Client client = getClient();
        VoltTable[] results = null;
       
        /*

        results = client.callProcedure("AggThings").getResults();
View Full Code Here

TOP

Related Classes of org.voltdb.client.Client

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.