Forum: Building APIs & Wire Protocol

Post: Testcase can't pass.And an question.

Testcase can't pass.And an question.
guotong1988
Nov 17, 2014
This testcase is based on https://github.com/VoltDB/voltdb/pull/1747.To test the max 'in' of query.

public class TestMaxInSuite extends RegressionSuite {

	static final Class<?>[] PROCEDURES = {};

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

	public void testMaxIn() throws Exception {
		final Client client = this.getClient();

		ClientResponse resp = null;
		for (int i = 0; i < 10; i++) {
			resp = client.callProcedure("P1.insert", i, i);
			assertEquals(ClientResponse.SUCCESS, resp.getStatus());
		}

		StringBuilder stringBuilder = new StringBuilder(
				"select * from p1 where a2 in(");
		for (int i = 0; i < 6000; i++) {
			stringBuilder.append(i);
			if (i != 5999) {
				stringBuilder.append(",");
			}
		}
		stringBuilder.append(");");
		resp = client.callProcedure("@AdHoc", stringBuilder.toString());
		assertEquals(ClientResponse.SUCCESS, resp.getStatus());

		assertEquals(1, resp.getResults().length);
		VoltTable results = resp.getResults()[0];
		int rowCount = results.getRowCount();
		assertEquals(10, rowCount);
		assertEquals(2, results.getColumnCount());
		for (int i = 0; i < rowCount; i++) {
			System.out.println(results.fetchRow(i).getLong(0));
			assertEquals(i, results.fetchRow(i).getLong(0));//70line
		}
	}

	static public junit.framework.Test suite() {
		VoltServerConfig config = null;
		final MultiConfigSuiteBuilder builder = new MultiConfigSuiteBuilder(
				TestMaxInSuite.class);

		final VoltProjectBuilder project = new VoltProjectBuilder();

		project.addStmtProcedure("CountP1", "select count(*) from p1;");
		// project.addStmtProcedure("CountR1", "select count(*) from r1;");//if
		// r1 doesn't exist , exception

		try {
			// a table that should generate procedures
			// use column names such that lexical order != column order.
			project.addLiteralSchema("CREATE TABLE p1(b1 INTEGER NOT NULL, a2 INTEGER NOT NULL, PRIMARY KEY (b1));");
			project.addPartitionInfo("p1", "b1");

		} catch (IOException error) {
			fail(error.getMessage());
		}

		// JNI
		config = new LocalCluster("testMax-onesite.jar", 1, 1, 0,
				BackendTarget.NATIVE_EE_JNI);
		boolean t1 = config.compile(project);
		assertTrue(t1);
		builder.addServerConfig(config);

		// CLUSTER
		config = new LocalCluster("testMax-cluster.jar", 2, 3, 1,
				BackendTarget.NATIVE_EE_JNI);
		boolean t2 = config.compile(project);
		assertTrue(t2);
		builder.addServerConfig(config);

		return builder;
	}
}

stacktrace:
junit.framework.AssertionFailedError: expected:<0> but was:<3>
at junit.framework.Assert.fail(Assert.java:50)
at junit.framework.Assert.failNotEquals(Assert.java:287)
at junit.framework.Assert.assertEquals(Assert.java:67)
at junit.framework.Assert.assertEquals(Assert.java:134)
at junit.framework.Assert.assertEquals(Assert.java:140)
at org.voltdb.regressionsuites.TestMaxInSuite.testMaxIn(TestMaxInSuite.java:70)




The testMaxIn method is called twice,As LocalCluster are executed twice.
First time it passed ,but second time it break on assertEquals(i, results.fetchRow(i).getLong(0));.
I am wondering whether the data is clear after one LocalCluster is executed?
If the data is cleared after one LocalCluster is executed ,when and where does it do the cleaning?
xin
Nov 18, 2014
I think your query is not deterministic, adding an ORDER BY primary key should help.

"select * from p1 where a2 in (...) order by b1".

FYI, http://docs.voltdb.com/UsingVoltDB/DesignProc.php
guotong1988
Nov 20, 2014
Hi I find the answer about data cleaning and shutdown of localcluster myself :

all things happens in

LocalCluster.java
public void startUp(boolean clearLocalDataDirectories, ReplicationRole role) {