private static void startServer() throws ClassNotFoundException, SQLException { server = new ServerThread(testjar, pb.getPathToDeployment(), BackendTarget.NATIVE_EE_JNI); server.start(); server.waitForInitialization(); Class.forName("org.voltdb.jdbc.Driver"); conn = DriverManager.getConnection("jdbc:voltdb://localhost:21212"); }
ServerThread startup() throws Exception { String simpleSchema = "create table dummy (" + "sval1 varchar(100) not null, " + "sval2 varchar(100) default 'foo', " + "sval3 varchar(100) default 'bar', " + "PRIMARY KEY(sval1));"; File schemaFile = VoltProjectBuilder.writeStringToTempFile(simpleSchema); String schemaPath = schemaFile.getPath(); schemaPath = URLEncoder.encode(schemaPath, "UTF-8"); VoltProjectBuilder builder = new VoltProjectBuilder(); builder.addSchema(schemaPath); builder.addPartitionInfo("dummy", "sval1"); builder.addStmtProcedure("Insert", "insert into dummy values (?,?,?);"); builder.addStmtProcedure("Select", "select * from dummy;"); builder.setHTTPDPort(8095); boolean success = builder.compile(Configuration.getPathToCatalogForTest("jsonperf.jar"), 1, 1, 0); assert (success); VoltDB.Configuration config = new VoltDB.Configuration(); config.m_pathToCatalog = Configuration.getPathToCatalogForTest("jsonperf.jar"); config.m_pathToDeployment = builder.getPathToDeployment(); ServerThread server = new ServerThread(config); server.start(); server.waitForInitialization(); Client client = ClientFactory.createClient(); client.createConnection("localhost"); ClientResponse response1; response1 = client.callProcedure("Insert", "FOO", "BAR", "BOO"); assert (response1.getStatus() == ClientResponse.SUCCESS); return server; }
@BeforeClass public static void startDatabase() throws Exception { prepare(); String pathToCatalog = Configuration.getPathToCatalogForTest("csv.jar"); String pathToDeployment = Configuration.getPathToCatalogForTest("csv.xml"); VoltProjectBuilder builder = new VoltProjectBuilder(); builder.addLiteralSchema( "create table BLAH (" + "clm_integer integer not null, " + "clm_tinyint tinyint default 0, " + "clm_smallint smallint default 0, " + "clm_bigint bigint default 0, " + "clm_string varchar(20) default null, " + "clm_decimal decimal default null, " + "clm_float float default null, " + "clm_timestamp timestamp default null, " + "PRIMARY KEY(clm_integer) " + ");"); builder.addPartitionInfo("BLAH", "clm_integer"); boolean success = builder.compile(pathToCatalog, 2, 1, 0); assertTrue(success); MiscUtils.copyFile(builder.getPathToDeployment(), pathToDeployment); Configuration config = new Configuration(); config.m_pathToCatalog = pathToCatalog; config.m_pathToDeployment = pathToDeployment; localServer = new ServerThread(config); client = null; localServer.start(); localServer.waitForInitialization(); client = ClientFactory.createClient(new ClientConfig()); client.createConnection("localhost"); }
@Override public void startUp() { assert (!m_running); if (m_running) { return; } // set to true to spew startup timing data boolean logtime = true; long startTime = 0; if (logtime) { startTime = System.currentTimeMillis(); System.out.println("********** Starting cluster at: " + startTime); } // create the in-process server // Configuration config = new Configuration(); // config.m_backend = m_target; // config.m_noLoadLibVOLTDB = (m_target == BackendTarget.HSQLDB_BACKEND); // config.m_pathToCatalog = m_jarFileName; // config.m_profilingLevel = ProcedureProfiler.Level.DISABLED; // config.m_port = HStoreConstants.DEFAULT_PORT; HStoreConf hstore_conf = HStoreConf.singleton(HStoreConf.isInitialized() == false); hstore_conf.loadFromArgs(this.confParams); // create all the out-of-process servers // Loop through all of the sites in the catalog and start them int offset = m_procBuilder.command().size() - 1; for (Site catalog_site : CatalogUtil.getAllSites(this.catalog)) { final int site_id = catalog_site.getId(); // If this is the first site, then start the HStoreSite in this JVM if (site_id == 0) { m_localServer = new ServerThread(hstore_conf, catalog_site); m_localServer.start(); } // Otherwise, fork a new JVM that will run our other HStoreSites. // Remember that it is one JVM per HStoreSite else { try { m_procBuilder.command().set(offset, "-Dsite.id=" + site_id); Process proc = m_procBuilder.start(); m_cluster.add(proc); // write output to obj/release/testoutput/<test name>-n.txt // this may need to be more unique? Also very useful to just // set this to a hardcoded path and use "tail -f" to debug. String testoutputdir = m_buildDir + File.separator + "testoutput"; // make sure the directory exists File dir = new File(testoutputdir); if (dir.exists()) { assert (dir.isDirectory()); } else { boolean status = dir.mkdirs(); assert (status); } PipeToFile ptf = new PipeToFile( testoutputdir + File.separator + getName() + "-" + site_id + ".txt", proc.getInputStream()); ptf.m_writer.write(m_procBuilder.command().toString() + "\n"); m_pipes.add(ptf); Thread t = new Thread(ptf); t.setName("ClusterPipe:" + String.valueOf(site_id)); t.start(); } catch (IOException ex) { System.out.println("Failed to start cluster process:" + ex.getMessage()); Logger.getLogger(LocalCluster.class.getName()).log(Level.SEVERE, null, ex); assert (false); } } } // spin until all the pipes see the magic "Server completed.." string. boolean allReady; do { if (logtime) System.out.println( "********** pre witness: " + (System.currentTimeMillis() - startTime) + " ms"); allReady = true; for (PipeToFile pipeToFile : m_pipes) { if (pipeToFile.m_witnessedReady.get() != true) { try { // wait for explicit notification synchronized (pipeToFile) { pipeToFile.wait(); } } catch (InterruptedException ex) { Logger.getLogger(LocalCluster.class.getName()).log(Level.SEVERE, null, ex); } allReady = false; break; } } } while (allReady == false); if (logtime) System.out.println( "********** post witness: " + (System.currentTimeMillis() - startTime) + " ms"); // Finally, make sure the local server thread is running and wait if it is not. m_localServer.waitForInitialization(); if (logtime) System.out.println("********** DONE: " + (System.currentTimeMillis() - startTime) + " ms"); m_running = true; }
/** * Assuming given tables have schema metadata, fill them with random data and compare a pure-java * schema migration with an EE schema migration. */ void migrateSchema(VoltTable t1, VoltTable t2, boolean withData) throws Exception { ServerThread server = null; Client client = null; TableHelper helper = new TableHelper(); try { if (withData) { helper.randomFill(t1, 1000, 1024); } String catPath1 = catalogPathForTable(t1, "t1.jar"); String catPath2 = catalogPathForTable(t2, "t2.jar"); byte[] catBytes2 = MiscUtils.fileToBytes(new File(catPath2)); DeploymentBuilder depBuilder = new DeploymentBuilder(1, 1, 0); depBuilder.setVoltRoot("/tmp/foobar"); // disable logging depBuilder.configureLogging("/tmp/foobar", "/tmp/foobar", false, false, 1, 1, 3); String deployment = depBuilder.getXML(); File deploymentFile = VoltProjectBuilder.writeStringToTempFile(deployment); VoltDB.Configuration config = new VoltDB.Configuration(); config.m_pathToDeployment = deploymentFile.getAbsolutePath(); config.m_pathToCatalog = catPath1; config.m_ipcPort = 10000; // config.m_backend = BackendTarget.NATIVE_EE_IPC; server = new ServerThread(config); server.start(); server.waitForInitialization(); System.out.printf("PRE: %s\n", TableHelper.ddlForTable(t1)); System.out.printf("POST: %s\n", TableHelper.ddlForTable(t2)); ClientConfig clientConfig = new ClientConfig(); client = ClientFactory.createClient(clientConfig); client.createConnection("localhost"); TableHelper.loadTable(client, t1); ClientResponseImpl response = (ClientResponseImpl) client.callProcedure("@UpdateApplicationCatalog", catBytes2, null); System.out.println(response.toJSONString()); VoltTable t3 = client.callProcedure("@AdHoc", "select * from FOO").getResults()[0]; t3 = TableHelper.sortTable(t3); // compute the migrated table entirely in Java for comparison purposes TableHelper.migrateTable(t1, t2); t2 = TableHelper.sortTable(t2); // compare the tables StringBuilder sb = new StringBuilder(); if (!TableHelper.deepEqualsWithErrorMsg(t2, t3, sb)) { System.out.println("Table Mismatch"); // System.out.printf("PRE: %s\n", t2.toFormattedString()); // System.out.printf("POST: %s\n", t3.toFormattedString()); System.out.println(sb.toString()); fail(); } } finally { if (client != null) { client.close(); } if (server != null) { server.shutdown(); } } }