Search in sources :

Example 41 with NoConnectionsException

use of org.voltdb.client.NoConnectionsException in project voltdb by VoltDB.

the class TestSQLTypesSuite method testMissingAttributeInsert_With_Null_Defaults.

public void testMissingAttributeInsert_With_Null_Defaults() throws NoConnectionsException, ProcCallException, IOException {
    Client client = this.getClient();
    Object[] params = new Object[COLS + 2];
    params[0] = "WITH_NULL_DEFAULTS";
    params[1] = pkey.incrementAndGet();
    for (int i = 0; i < COLS; i++) {
        params[i + 2] = m_nullValues[i];
        assert (params[i + 2] != null);
    }
    try {
        client.callProcedure("Insert", params);
    } catch (ProcCallException e) {
        e.printStackTrace();
        fail();
    } catch (NoConnectionsException e) {
        e.printStackTrace();
        fail();
    }
    VoltTable[] result = client.callProcedure("Select", "WITH_NULL_DEFAULTS", pkey.get()).getResults();
    VoltTableRow row = result[0].fetchRow(0);
    for (int i = 0; i < COLS; ++i) {
        Object obj = row.get(i + 1, m_types[i]);
        assertTrue("Expected to be equal: (" + obj + ", " + params[i + 2] + ")", comparisonHelper(obj, params[i + 2], m_types[i]));
    }
}
Also used : NoConnectionsException(org.voltdb.client.NoConnectionsException) Client(org.voltdb.client.Client) VoltTable(org.voltdb.VoltTable) VoltTableRow(org.voltdb.VoltTableRow) ProcCallException(org.voltdb.client.ProcCallException)

Example 42 with NoConnectionsException

use of org.voltdb.client.NoConnectionsException in project voltdb by VoltDB.

the class TestSQLTypesSuite method testEng5013.

public void testEng5013() throws NoConnectionsException, ProcCallException, IOException {
    Client client = this.getClient();
    client.callProcedure("InsertDecimal", 1, 3.4f);
    client.callProcedure("InsertDecimal", 2, 3.4d);
    client.callProcedure("InsertDecimal", 3, 1f);
    client.callProcedure("InsertDecimal", 4, 1d);
    client.callProcedure("InsertDecimal", 5, 0.25f);
    client.callProcedure("InsertDecimal", 6, 0.25d);
    client.callProcedure("InsertDecimal", 7, 3.3f);
    client.callProcedure("InsertDecimal", 8, 3.3d);
    try {
        client.callProcedure("InsertDecimal", 9, Double.MAX_VALUE);
        fail();
    } catch (ProcCallException e) {
        // should give out of precision range error
        assertTrue(e.getMessage().contains("has more than 38 digits of precision"));
    } catch (Exception e) {
        fail();
    }
    try {
        client.callProcedure("InsertDecimal", 9, -Double.MAX_VALUE);
        fail();
    } catch (ProcCallException e) {
        // should give out of precision range error
        assertTrue(e.getMessage().contains("has more than 38 digits of precision"));
    } catch (Exception e) {
        fail();
    }
    try {
        client.callProcedure("InsertDecimal", 9, Float.MAX_VALUE);
        fail();
    } catch (ProcCallException e) {
        // should give out of precision range error
        assertTrue(e.getMessage().contains("has more than 38 digits of precision"));
    } catch (Exception e) {
        fail();
    }
    try {
        client.callProcedure("InsertDecimal", 9, -Float.MAX_VALUE);
        fail();
    } catch (ProcCallException e) {
        // should give out of precision range error
        assertTrue(e.getMessage().contains("has more than 38 digits of precision"));
    } catch (Exception e) {
        fail();
    }
    double nand = 0.0d / 0.0d;
    float nanf = 0.0f / 0.0f;
    try {
        client.callProcedure("InsertDecimal", 9, nand);
    } catch (ProcCallException e) {
        // passing a NaN value will cause NumberFormatException, and fail the proceudre call
        assertTrue(e.getMessage().contains("NumberFormatException"));
    } catch (Exception e) {
        fail();
    }
    try {
        client.callProcedure("InsertDecimal", 9, nanf);
        fail();
    } catch (ProcCallException e) {
        // passing a NaN value will cause NumberFormatException, and fail the proceudre call
        assertTrue(e.getMessage().contains("NumberFormatException"));
    } catch (Exception e) {
        fail();
    }
    client.callProcedure("InsertDecimal", 9, Double.MIN_VALUE);
    client.callProcedure("InsertDecimal", 10, Float.MIN_VALUE);
    // will lose some precision by truncated to .12f
    client.callProcedure("InsertDecimal", 11, 123456789.01234567890123456789f);
    VoltTable table;
    table = client.callProcedure("@AdHoc", "SELECT A_DECIMAL FROM WITH_DEFAULTS WHERE PKEY = 11").getResults()[0];
    assertTrue(table.getRowCount() == 1);
    table.advanceRow();
    float f = table.getDecimalAsBigDecimal(0).floatValue();
    assertEquals(123456789.01234567890123456789f, f, 0.000000000001);
    // will lose some precision by truncated to .12f
    client.callProcedure("InsertDecimal", 12, 123456789.01234567890123456789d);
    table = client.callProcedure("@AdHoc", "SELECT A_DECIMAL FROM WITH_DEFAULTS WHERE PKEY = 12").getResults()[0];
    assertTrue(table.getRowCount() == 1);
    table.advanceRow();
    double d = table.getDecimalAsBigDecimal(0).doubleValue();
    assertEquals(123456789.01234567890123456789d, d, 0.000000000001);
}
Also used : Client(org.voltdb.client.Client) VoltTable(org.voltdb.VoltTable) ProcCallException(org.voltdb.client.ProcCallException) IOException(java.io.IOException) ProcCallException(org.voltdb.client.ProcCallException) NoConnectionsException(org.voltdb.client.NoConnectionsException)

Example 43 with NoConnectionsException

use of org.voltdb.client.NoConnectionsException in project voltdb by VoltDB.

the class TestSQLTypesSuite method testInsertNulls_Nulls_Allowed.

//
// Verify that NULLS are allowed in non-NOT NULL columns
//
public void testInsertNulls_Nulls_Allowed() throws IOException {
    final Client client = this.getClient();
    // Insert a NULL value for each column. For the first
    // row, insert null in the first column, for the 5th row
    // in the 5 column, etc.
    final Object[] params = new Object[COLS + 2];
    for (int k = 0; k < COLS; ++k) {
        // build the parameter list as described above
        params[0] = "";
        params[1] = pkey.incrementAndGet();
        for (int i = 0; i < COLS; i++) {
            params[i + 2] = (i == k) ? m_nullValues[i] : m_midValues[i];
            assert (params[i + 2] != null);
        }
        // Each insert in to the ALLOW_NULLS table must succeed.
        // Perform the inserts and execute selects, verifying the
        // content of the select matches the parameters passed to
        // insert
        System.out.println("testNullsAllowed: " + k + " NULL type is " + m_types[k]);
        try {
            params[0] = "ALLOW_NULLS";
            // We'll use the multi-partition insert for this test. Between
            // this and testInsertNull_No_Nulls we should cover both
            // cases in ticket 306
            client.callProcedure("InsertMulti", params);
        } catch (final ProcCallException e) {
            e.printStackTrace();
            fail();
        } catch (final NoConnectionsException e) {
            e.printStackTrace();
            fail();
        }
        // verify that the row was inserted
        try {
            final VoltTable[] result = client.callProcedure("Select", "ALLOW_NULLS", pkey.get()).getResults();
            final VoltTableRow row = result[0].fetchRow(0);
            for (int i = 0; i < COLS; ++i) {
                final Object obj = row.get(i + 1, m_types[i]);
                if (i == k) {
                    assertTrue(row.wasNull());
                    System.out.println("Row " + i + " verifed as NULL");
                } else {
                    assertTrue(comparisonHelper(obj, params[i + 2], m_types[i]));
                }
            }
        } catch (final Exception ex) {
            ex.printStackTrace();
            fail();
        }
    }
}
Also used : NoConnectionsException(org.voltdb.client.NoConnectionsException) Client(org.voltdb.client.Client) VoltTable(org.voltdb.VoltTable) VoltTableRow(org.voltdb.VoltTableRow) ProcCallException(org.voltdb.client.ProcCallException) IOException(java.io.IOException) ProcCallException(org.voltdb.client.ProcCallException) NoConnectionsException(org.voltdb.client.NoConnectionsException)

Example 44 with NoConnectionsException

use of org.voltdb.client.NoConnectionsException in project voltdb by VoltDB.

the class DeletesClient method deleteDeceased.

static void deleteDeceased(Client client) {
    Date date = new Date();
    System.out.println(date.toString() + "\n\tDeleting deceased records...");
    m_expectedDeadDeletes = NUM_NAMES;
    long start_time = System.currentTimeMillis();
    for (int i = 0; i < NUM_NAMES; i++) {
        try {
            while (!client.callProcedure(new ProcedureCallback() {

                @Override
                public void clientCallback(ClientResponse response) {
                    if (response.getStatus() != ClientResponse.SUCCESS) {
                        System.out.println("failed delete deceased");
                        System.out.println(response.getStatusString());
                    } else {
                        m_totalRows -= response.getResults()[0].asScalarLong();
                    }
                    //we don't care if tx fail, but don't get stuck in yield
                    m_expectedDeadDeletes--;
                }
            }, "DeleteDeceased", m_names[i])) {
                try {
                    client.backpressureBarrier();
                } catch (InterruptedException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
            }
        } catch (NoConnectionsException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
    while (m_expectedDeadDeletes != 0) {
        Thread.yield();
    }
    long elapsed = System.currentTimeMillis() - start_time;
    m_totalDeadDeletes += NUM_NAMES;
    m_totalDeadDeleteTime += elapsed;
    System.out.println("\tAfter dead deletes, total rows: " + m_totalRows);
    System.out.println("\tDeleting deceased: " + NUM_NAMES + " took " + elapsed + " millis");
    System.out.println("\t\t (" + ((NUM_NAMES * 1000) / elapsed) + " tps)");
    System.out.println("\tTotal delete TPS: " + (m_totalDeadDeletes * 1000) / m_totalDeadDeleteTime);
}
Also used : ProcedureCallback(org.voltdb.client.ProcedureCallback) ClientResponse(org.voltdb.client.ClientResponse) NoConnectionsException(org.voltdb.client.NoConnectionsException) IOException(java.io.IOException) Date(java.util.Date)

Example 45 with NoConnectionsException

use of org.voltdb.client.NoConnectionsException in project voltdb by VoltDB.

the class DeletesClient method countBatch.

static void countBatch(Client client, long batch) {
    Date date = new Date();
    System.out.println(date.toString() + "\n\tCounting batch: " + batch);
    m_expectedCounts = 1;
    long start_time = System.currentTimeMillis();
    for (int i = 0; i < 1; i++) {
        try {
            while (!client.callProcedure(new ProcedureCallback() {

                @Override
                public void clientCallback(ClientResponse response) {
                    if (response.getStatus() != ClientResponse.SUCCESS) {
                        System.out.println("failed count batch");
                        System.out.println(response.getStatusString());
                    } else {
                        System.out.println("\tBatch has " + response.getResults()[0].asScalarLong() + " items");
                    }
                    //we don't care if tx fail, but don't get stuck in yield
                    m_expectedCounts--;
                }
            }, "CountBatchSize", "", batch)) {
                try {
                    client.backpressureBarrier();
                } catch (InterruptedException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
            }
        } catch (NoConnectionsException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
    while (m_expectedCounts != 0) {
        Thread.yield();
    }
    long elapsed = System.currentTimeMillis() - start_time;
}
Also used : ProcedureCallback(org.voltdb.client.ProcedureCallback) ClientResponse(org.voltdb.client.ClientResponse) NoConnectionsException(org.voltdb.client.NoConnectionsException) IOException(java.io.IOException) Date(java.util.Date)

Aggregations

NoConnectionsException (org.voltdb.client.NoConnectionsException)50 IOException (java.io.IOException)41 ProcCallException (org.voltdb.client.ProcCallException)38 VoltTable (org.voltdb.VoltTable)27 ClientResponse (org.voltdb.client.ClientResponse)21 Client (org.voltdb.client.Client)19 Date (java.util.Date)7 VoltTableRow (org.voltdb.VoltTableRow)6 ProcedureCallback (org.voltdb.client.ProcedureCallback)5 Timestamp (java.sql.Timestamp)4 File (java.io.File)3 AtomicLong (java.util.concurrent.atomic.AtomicLong)3 Tag (org.openstreetmap.osmosis.core.domain.v0_6.Tag)3 ClientResponseImpl (org.voltdb.ClientResponseImpl)3 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)2 WayNode (org.openstreetmap.osmosis.core.domain.v0_6.WayNode)2 LineString (org.postgis.LineString)2 VoltCompiler (org.voltdb.compiler.VoltCompiler)2