private void testDynamicNameRevocation( KeyStore serverKeyStore, KeyStore serverTrustStore, KeyStore clientKeyStore, KeyStore clientTrustStore, String revokeName) throws Exception { logger.info("testRevoke: " + revokeName); Set<String> revokedNames = new ConcurrentSkipListSet(); SSLContext serverSSLContext = RevocableNameSSLContexts.create(serverKeyStore, pass, serverTrustStore, revokedNames); SSLContext clientSSLContext = SSLContexts.create(clientKeyStore, pass, clientTrustStore); ServerThread serverThread = new ServerThread(); try { serverThread.start(serverSSLContext, port, 2); Assert.assertNull(ClientThread.connect(clientSSLContext, port)); Assert.assertNull(serverThread.getErrorMessage()); revokedNames.add(revokeName); logger.debug("revokedNames: " + revokedNames); Thread.sleep(1000); Assert.assertNotNull(ClientThread.connect(clientSSLContext, port)); Assert.assertNotNull(serverThread.getErrorMessage()); } finally { serverThread.close(); serverThread.join(1000); } }
private void doLogonTest(String keyStoreName, String keyStorePassword) throws InterruptedException, ConfigError { ServerThread serverThread = new ServerThread(keyStoreName, keyStorePassword); try { serverThread.setDaemon(true); serverThread.start(); serverThread.waitForInitialization(); SessionID clientSessionID = new SessionID(FixVersions.BEGINSTRING_FIX42, "TW", "ISLD"); SessionSettings settings = getClientSessionSettings(clientSessionID); ClientApplication clientApplication = new ClientApplication(); ThreadedSocketInitiator initiator = new ThreadedSocketInitiator( clientApplication, new MemoryStoreFactory(), settings, new DefaultMessageFactory()); try { log.info("Do login"); clientApplication.setUpLogonExpectation(); initiator.start(); Session clientSession = Session.lookupSession(clientSessionID); assertLoggedOn(clientApplication, clientSession); } finally { initiator.stop(); } } finally { serverThread.interrupt(); serverThread.join(); } }
/** Closes all open sockets and stops the internal server thread that processes messages. */ public void close() { ServerThread st = server; if (st != null) { st.close(); try { st.join(); } catch (InterruptedException ex) { logger.warn(ex); } server = null; for (Iterator it = sockets.values().iterator(); it.hasNext(); ) { SocketEntry entry = (SocketEntry) it.next(); try { synchronized (entry) { entry.getSocket().close(); } logger.debug("Socket to " + entry.getPeerAddress() + " closed"); } catch (IOException iox) { // ingore logger.debug(iox); } } if (socketCleaner != null) { socketCleaner.cancel(); } socketCleaner = null; } }
public void testRejoinSysprocButFail() throws Exception { VoltProjectBuilder builder = getBuilderForTest(); boolean success = builder.compile(Configuration.getPathToCatalogForTest("rejoin.jar"), 1, 1, 0); assertTrue(success); MiscUtils.copyFile( builder.getPathToDeployment(), Configuration.getPathToCatalogForTest("rejoin.xml")); VoltDB.Configuration config = new VoltDB.Configuration(); config.m_pathToCatalog = Configuration.getPathToCatalogForTest("rejoin.jar"); config.m_pathToDeployment = Configuration.getPathToCatalogForTest("rejoin.xml"); config.m_isRejoinTest = true; ServerThread localServer = new ServerThread(config); localServer.start(); localServer.waitForInitialization(); Client client = ClientFactory.createClient(); client.createConnection("localhost"); SyncCallback scb = new SyncCallback(); success = false; while (!success) { success = client.callProcedure(scb, "@Rejoin", "localhost", config.m_internalPort + 1); if (!success) Thread.sleep(100); } scb.waitForResponse(); ClientResponse response = scb.getResponse(); assertTrue(response.getStatusString().contains("Unable to find down node")); client.close(); localServer.shutdown(); localServer.join(); }
public void testLogonWithBadCertificate() throws Exception { ServerThread serverThread = new ServerThread("nonexistent", "pwd"); try { serverThread.setDaemon(true); serverThread.start(); serverThread.waitForInitialization(); SessionID clientSessionID = new SessionID(FixVersions.BEGINSTRING_FIX42, "TW", "ISLD"); SessionSettings settings = getClientSessionSettings(clientSessionID); ClientApplication clientApplication = new ClientApplication(); ThreadedSocketInitiator initiator = new ThreadedSocketInitiator( clientApplication, new MemoryStoreFactory(), settings, new DefaultMessageFactory()); final CountDownLatch exceptionCaught = new CountDownLatch(1); initiator.setIoFilterChainBuilder( new IoFilterChainBuilder() { public void buildFilterChain(IoFilterChain chain) throws Exception { chain.addLast( "ExceptionCatcher", new IoFilterAdapter() { public void exceptionCaught( NextFilter nextFilter, IoSession session, Throwable cause) throws Exception { log.info("MINA exception: " + cause.getMessage()); exceptionCaught.countDown(); } }); } }); try { log.info("Do login"); initiator.start(); assertTrue("no exception thrown", exceptionCaught.await(5, TimeUnit.SECONDS)); } finally { initiator.stop(); } } finally { serverThread.interrupt(); serverThread.join(); } }
public void testClientServer() throws Exception { SecureRandom secureRandom = new SecureRandom(); PipedInputStream clientRead = new PipedInputStream(); PipedInputStream serverRead = new PipedInputStream(); PipedOutputStream clientWrite = new PipedOutputStream(serverRead); PipedOutputStream serverWrite = new PipedOutputStream(clientRead); TlsClientProtocol clientProtocol = new TlsClientProtocol(clientRead, clientWrite, secureRandom); TlsServerProtocol serverProtocol = new TlsServerProtocol(serverRead, serverWrite, secureRandom); ServerThread serverThread = new ServerThread(serverProtocol); serverThread.start(); MockTlsClient client = new MockTlsClient(null); clientProtocol.connect(client); // NOTE: Because we write-all before we read-any, this length can't be more than the pipe // capacity int length = 1000; byte[] data = new byte[length]; secureRandom.nextBytes(data); OutputStream output = clientProtocol.getOutputStream(); output.write(data); byte[] echo = new byte[data.length]; int count = Streams.readFully(clientProtocol.getInputStream(), echo); assertEquals(count, data.length); assertTrue(Arrays.areEqual(data, echo)); output.close(); serverThread.join(); }
public void testRoundTripCJKWithJSONInsert() throws Exception { ServerThread server = startup(); ParameterSet pset; String responseJSON; Response response; VoltTable[] results; VoltTable result; String c, j, k; // Call insert pset = ParameterSet.fromArrayNoCopy( POORLY_TRANSLATED_CHINESE, POORLY_TRANSLATED_JAPANESE, POORLY_TRANSLATED_KOREAN); responseJSON = TestJSONInterface.callProcOverJSON("Insert", pset, null, null, false); System.out.println(responseJSON); response = TestJSONInterface.responseFromJSON(responseJSON); assertTrue(response.status == ClientResponse.SUCCESS); // Call select pset = ParameterSet.emptyParameterSet(); responseJSON = TestJSONInterface.callProcOverJSON("Select", pset, null, null, false); System.out.println(responseJSON); response = TestJSONInterface.responseFromJSON(responseJSON); assertTrue(response.status == ClientResponse.SUCCESS); results = response.results; assertEquals(1, results.length); result = results[0]; assertEquals(1, result.getRowCount()); assertEquals(3, result.getColumnCount()); result.advanceRow(); c = result.getString(0); j = result.getString(1); k = result.getString(2); System.out.printf("c: %s\nj: %s\nk: %s\n", c, j, k); assertEquals(0, c.compareTo(POORLY_TRANSLATED_CHINESE)); assertEquals(0, j.compareTo(POORLY_TRANSLATED_JAPANESE)); assertEquals(0, k.compareTo(POORLY_TRANSLATED_KOREAN)); Client client = ClientFactory.createClient(); client.createConnection("localhost"); ClientResponse response1; response1 = client.callProcedure("Select"); assertEquals(response1.getStatus(), ClientResponse.SUCCESS); results = response1.getResults(); assertEquals(1, results.length); result = results[0]; assertEquals(1, result.getRowCount()); assertEquals(3, result.getColumnCount()); result.advanceRow(); c = result.getString(0); j = result.getString(1); k = result.getString(2); System.out.printf("c: %s\nj: %s\nk: %s\n", c, j, k); assertEquals(0, c.compareTo(POORLY_TRANSLATED_CHINESE)); assertEquals(0, j.compareTo(POORLY_TRANSLATED_JAPANESE)); assertEquals(0, k.compareTo(POORLY_TRANSLATED_KOREAN)); server.shutdown(); server.join(); }
public void testSimple() throws Exception { String simpleSchema = "create table BLAH (" + "IVAL bigint default 0 not null, " + "TVAL timestamp default null," + "DVAL decimal default null," + "PRIMARY KEY(IVAL));"; VoltProjectBuilder builder = new VoltProjectBuilder(); builder.addLiteralSchema(simpleSchema); builder.addPartitionInfo("BLAH", "IVAL"); builder.addStmtProcedure("Insert", "insert into blah values (?, ?, ?);", null); builder.addStmtProcedure( "InsertWithDate", "INSERT INTO BLAH VALUES (974599638818488300, '2011-06-24 10:30:26.002', 5);"); boolean success = builder.compile(Configuration.getPathToCatalogForTest("adhoc.jar"), 2, 1, 0); assertTrue(success); MiscUtils.copyFile( builder.getPathToDeployment(), Configuration.getPathToCatalogForTest("adhoc.xml")); VoltDB.Configuration config = new VoltDB.Configuration(); config.m_pathToCatalog = Configuration.getPathToCatalogForTest("adhoc.jar"); config.m_pathToDeployment = Configuration.getPathToCatalogForTest("adhoc.xml"); ServerThread localServer = new ServerThread(config); localServer.start(); localServer.waitForInitialization(); // do the test Client client = ClientFactory.createClient(); client.createConnection("localhost"); VoltTable modCount = client.callProcedure("@AdHoc", "INSERT INTO BLAH VALUES (1, 1, 1);").getResults()[0]; assertTrue(modCount.getRowCount() == 1); assertTrue(modCount.asScalarLong() == 1); VoltTable result = client.callProcedure("@AdHoc", "SELECT * FROM BLAH;").getResults()[0]; assertTrue(result.getRowCount() == 1); System.out.println(result.toString()); // test single-partition stuff result = client.callProcedure("@AdHoc", "SELECT * FROM BLAH;", 0).getResults()[0]; assertTrue(result.getRowCount() == 0); System.out.println(result.toString()); result = client.callProcedure("@AdHoc", "SELECT * FROM BLAH;", 1).getResults()[0]; assertTrue(result.getRowCount() == 1); System.out.println(result.toString()); try { client.callProcedure("@AdHoc", "INSERT INTO BLAH VALUES (0, 0, 0);", 1); fail("Badly partitioned insert failed to throw expected exception"); } catch (Exception e) { } try { client.callProcedure("@AdHoc", "SLEECT * FROOM NEEEW_OOORDERERER;"); fail("Bad SQL failed to throw expected exception"); } catch (Exception e) { } // try a huge bigint literal modCount = client.callProcedure( "@AdHoc", "INSERT INTO BLAH VALUES (974599638818488300, '2011-06-24 10:30:26.123012', 5);") .getResults()[0]; modCount = client.callProcedure( "@AdHoc", "INSERT INTO BLAH VALUES (974599638818488301, '2011-06-24 10:30:28', 5);") .getResults()[0]; assertTrue(modCount.getRowCount() == 1); assertTrue(modCount.asScalarLong() == 1); result = client.callProcedure("@AdHoc", "SELECT * FROM BLAH WHERE IVAL = 974599638818488300;") .getResults()[0]; assertTrue(result.getRowCount() == 1); System.out.println(result.toString()); result = client.callProcedure( "@AdHoc", "SELECT * FROM BLAH WHERE TVAL = '2011-06-24 10:30:26.123012';") .getResults()[0]; assertTrue(result.getRowCount() == 1); System.out.println(result.toString()); result = client.callProcedure("@AdHoc", "SELECT * FROM BLAH WHERE TVAL > '2011-06-24 10:30:25';") .getResults()[0]; assertEquals(2, result.getRowCount()); System.out.println(result.toString()); result = client.callProcedure("@AdHoc", "SELECT * FROM BLAH WHERE TVAL < '2011-06-24 10:30:27';") .getResults()[0]; System.out.println(result.toString()); // We inserted a 1,1,1 row way earlier assertEquals(2, result.getRowCount()); // try something like the queries in ENG-1242 try { client.callProcedure( "@AdHoc", "select * from blah; dfvsdfgvdf select * from blah WHERE IVAL = 1;"); fail("Bad SQL failed to throw expected exception"); } catch (Exception e) { } client.callProcedure("@AdHoc", "select\n* from blah;"); // try a decimal calculation (ENG-1093) modCount = client.callProcedure( "@AdHoc", "INSERT INTO BLAH VALUES (2, '2011-06-24 10:30:26', 1.12345*1);") .getResults()[0]; assertTrue(modCount.getRowCount() == 1); assertTrue(modCount.asScalarLong() == 1); result = client.callProcedure("@AdHoc", "SELECT * FROM BLAH WHERE IVAL = 2;").getResults()[0]; assertTrue(result.getRowCount() == 1); System.out.println(result.toString()); localServer.shutdown(); localServer.join(); }
@Test public void testProcedureAdhoc() throws Exception { VoltDB.Configuration config = setUpSPDB(m_useIv2); ServerThread localServer = new ServerThread(config); try { localServer.start(); localServer.waitForInitialization(); // do the test m_client = ClientFactory.createClient(); m_client.createConnection("localhost", config.m_port); m_client.callProcedure("@AdHoc", "insert into PARTED1 values ( 23, 3 )"); /* * Test that a basic multipartition select works as well as a parameterized * query (it's in the procedure) */ VoltTable results[] = m_client.callProcedure("executeSQLSP", 23, "select * from PARTED1").getResults(); assertTrue(results[0].advanceRow()); assertTrue(results[1].advanceRow()); results = m_client.callProcedure("executeSQLMP", 23, " select * from PARTED1").getResults(); assertTrue(results[0].advanceRow()); assertTrue(results[1].advanceRow()); /* * Validate that doing an insert from a RO procedure fails */ try { m_client.callProcedure("executeSQLSP", 24, "insert into parted1 values (24,5)"); fail("Procedure call should not have succeded"); } catch (ProcCallException e) { } try { m_client.callProcedure("executeSQLMP", 24, "insert into parted1 values (24,5)"); fail("Procedure call should not have succeded"); } catch (ProcCallException e) { } /* * Validate one sql statement per */ try { m_client.callProcedure( "executeSQLSP", 24, "insert into parted1 values (24,5); select * from parted1;"); fail("Procedure call should not have succeded"); } catch (ProcCallException e) { } try { m_client.callProcedure("executeSQLSP", 24, "drop table parted1"); fail("Procedure call should not have succeded"); } catch (ProcCallException e) { } /* * Validate that an insert does work from a write procedure */ m_client.callProcedure("executeSQLSPWRITE", 24, "insert into parted1 values (24, 4);"); m_client.callProcedure("executeSQLMPWRITE", 25, "insert into parted1 values (25, 5);"); /* * Query the inserts and all the rest do it once for singe and once for multi */ results = m_client .callProcedure("executeSQLMP", 24, "select * from parted1 order by partval") .getResults(); assertEquals(3, results[0].getRowCount()); for (int ii = 3; ii < 6; ii++) { assertTrue(results[0].advanceRow()); assertEquals(20 + ii, results[0].getLong(0)); assertEquals(ii, results[0].getLong(1)); } // Output from the first preplanned statement assertEquals(3, results[1].getRowCount()); assertTrue(results[1].advanceRow()); assertEquals(23, results[1].getLong(0)); assertEquals(3, results[1].getLong(1)); // Output from the second adhoc statement assertEquals(1, results[2].getRowCount()); assertTrue(results[2].advanceRow()); assertEquals(24, results[2].getLong(0)); assertEquals(4, results[2].getLong(1)); // Output from the second preplanned statement assertEquals(3, results[3].getRowCount()); assertTrue(results[3].advanceRow()); assertEquals(23, results[3].getLong(0)); assertEquals(3, results[3].getLong(1)); results = m_client .callProcedure("executeSQLSP", 24, "select * from parted1 order by partval") .getResults(); assertEquals(1, results[0].getRowCount()); assertTrue(results[0].advanceRow()); assertEquals(24, results[0].getLong(0)); assertEquals(4, results[0].getLong(1)); // Output from the first preplanned statement assertEquals(1, results[1].getRowCount()); assertTrue(results[1].advanceRow()); assertEquals(24, results[1].getLong(0)); assertEquals(4, results[1].getLong(1)); // Output from the second adhoc statement assertEquals(1, results[2].getRowCount()); assertTrue(results[2].advanceRow()); assertEquals(24, results[2].getLong(0)); assertEquals(4, results[2].getLong(1)); // Output from the second preplanned statement assertEquals(1, results[3].getRowCount()); assertTrue(results[3].advanceRow()); assertEquals(24, results[3].getLong(0)); assertEquals(4, results[3].getLong(1)); } catch (Exception e) { e.printStackTrace(); fail(); } finally { if (m_client != null) m_client.close(); m_client = null; if (localServer != null) { localServer.shutdown(); localServer.join(); } localServer = null; // no clue how helpful this is System.gc(); } }
@Test public void testSP() throws Exception { VoltDB.Configuration config = setUpSPDB(m_useIv2); ServerThread localServer = new ServerThread(config); try { localServer.start(); localServer.waitForInitialization(); // do the test m_client = ClientFactory.createClient(); m_client.createConnection("localhost", config.m_port); VoltTable modCount; // Unlike TestAdHocPlans, TestAdHocQueries runs the queries against actual (minimal) data. // Load that, here. modCount = m_client.callProcedure("@AdHoc", "INSERT INTO PARTED1 VALUES (0, 0);").getResults()[0]; assertEquals(1, modCount.getRowCount()); assertEquals(1, modCount.asScalarLong()); modCount = m_client.callProcedure("@AdHoc", "INSERT INTO PARTED1 VALUES (1, 1);").getResults()[0]; assertEquals(1, modCount.getRowCount()); assertEquals(1, modCount.asScalarLong()); modCount = m_client.callProcedure("@AdHoc", "INSERT INTO PARTED2 VALUES (0, 0);").getResults()[0]; assertEquals(1, modCount.getRowCount()); assertEquals(1, modCount.asScalarLong()); modCount = m_client.callProcedure("@AdHoc", "INSERT INTO PARTED2 VALUES (2, 2);").getResults()[0]; assertEquals(1, modCount.getRowCount()); assertEquals(1, modCount.asScalarLong()); modCount = m_client.callProcedure("@AdHoc", "INSERT INTO PARTED3 VALUES (0, 0);").getResults()[0]; assertEquals(1, modCount.getRowCount()); assertEquals(1, modCount.asScalarLong()); modCount = m_client.callProcedure("@AdHoc", "INSERT INTO PARTED3 VALUES (3, 3);").getResults()[0]; assertEquals(1, modCount.getRowCount()); assertEquals(1, modCount.asScalarLong()); modCount = m_client.callProcedure("@AdHoc", "INSERT INTO REPPED1 VALUES (0, 0);").getResults()[0]; assertEquals(1, modCount.getRowCount()); assertEquals(1, modCount.asScalarLong()); modCount = m_client.callProcedure("@AdHoc", "INSERT INTO REPPED1 VALUES (1, 1);").getResults()[0]; assertEquals(1, modCount.getRowCount()); assertEquals(1, modCount.asScalarLong()); modCount = m_client.callProcedure("@AdHoc", "INSERT INTO REPPED2 VALUES (0, 0);").getResults()[0]; assertEquals(1, modCount.getRowCount()); assertEquals(1, modCount.asScalarLong()); modCount = m_client.callProcedure("@AdHoc", "INSERT INTO REPPED2 VALUES (2, 2);").getResults()[0]; assertEquals(1, modCount.getRowCount()); assertEquals(1, modCount.asScalarLong()); runAllAdHocSPtests(); } finally { if (m_client != null) m_client.close(); m_client = null; if (localServer != null) { localServer.shutdown(); localServer.join(); } localServer = null; // no clue how helpful this is System.gc(); } }