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; }
public LocalCluster( String jarFileName, int siteCount, int partitionsPerSite, int replication, BackendTarget target) { System.out.println("Instantiating LocalCluster for " + jarFileName); System.out.println( "Sites: " + siteCount + " hosts: " + partitionsPerSite + " replication factor: " + replication); assert (jarFileName != null); assert (siteCount > 0); assert (partitionsPerSite > 0); assert (replication >= 0); /*// (1) Load catalog from Jar Catalog tmpCatalog = CatalogUtil.loadCatalogFromJar(jarFileName); // (2) Update catalog to include target cluster configuration ClusterConfiguration cc = new ClusterConfiguration(); // Update cc with a bunch of hosts/sites/partitions for (int site = 0, currentPartition = 0; site < hostCount; ++site) { for (int partition = 0; partition < siteCount; ++partition, ++currentPartition) { cc.addPartition("localhost", site, currentPartition); } } System.err.println(cc.toString()); this.catalog = FixCatalog.addHostInfo(tmpCatalog, cc); System.err.println(CatalogInfo.getInfo(this.catalog, new File(jarFileName))); System.err.println(catalog.serialize()); // (3) Write updated catalog back out to jar file try { CatalogUtil.updateCatalogInJar(jarFileName, catalog, "catalog.txt"); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } tmpCatalog = CatalogUtil.loadCatalogFromJar(jarFileName); System.err.println("XXXXXXXXXXXXXXXXXXXXX\n" + CatalogInfo.getInfo(this.catalog, new File(jarFileName)));*/ m_jarFileName = VoltDB.Configuration.getPathToCatalogForTest(jarFileName); m_partitionPerSite = siteCount; m_target = target; m_siteCount = partitionsPerSite; m_replication = replication; String buildDir = System.getenv("VOLTDB_BUILD_DIR"); // via build.xml if (buildDir == null) m_buildDir = System.getProperty("user.dir") + "/obj/release"; else m_buildDir = buildDir; // processes of VoltDBs using the compiled jar file. m_cluster = new ArrayList<Process>(); m_pipes = new ArrayList<PipeToFile>(); Thread shutdownThread = new Thread(new ShutDownHookThread()); java.lang.Runtime.getRuntime().addShutdownHook(shutdownThread); }
/** * 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(); } } }