public void testSendingSameStreamDefinitions() throws MalformedURLException, AuthenticationException, TransportException, AgentException, UndefinedEventTypeException, DifferentStreamDefinitionAlreadyDefinedException, InterruptedException, DataBridgeException, MalformedStreamDefinitionException, StreamDefinitionException { TestServer testServer = new TestServer(); testServer.start(7614); KeyStoreUtil.setTrustStoreParams(); Thread.sleep(2000); // according to the convention the authentication port will be 7611+100= 7711 and its host will // be the same DataPublisher dataPublisher = new DataPublisher("tcp://localhost:7614", "admin", "admin"); String id1 = dataPublisher.defineStream( "{" + " 'name':'org.wso2.esb.MediatorStatistics'," + " 'version':'2.3.0'," + " 'nickName': 'Stock Quote Information'," + " 'description': 'Some Desc'," + " 'tags':['foo', 'bar']," + " 'metaData':[" + " {'name':'ipAdd','type':'STRING'}" + " ]," + " 'payloadData':[" + " {'name':'symbol','type':'STRING'}," + " {'name':'price','type':'DOUBLE'}," + " {'name':'volume','type':'INT'}," + " {'name':'max','type':'DOUBLE'}," + " {'name':'min','type':'Double'}" + " ]" + "}"); String id2 = dataPublisher.defineStream( "{" + " 'name':'org.wso2.esb.MediatorStatistics'," + " 'version':'2.3.0'," + " 'nickName': 'Stock Quote Information'," + " 'description': 'Some Desc'," + " 'tags':['foo', 'bar']," + " 'metaData':[" + " {'name':'ipAdd','type':'STRING'}" + " ]," + " 'payloadData':[" + " {'name':'symbol','type':'STRING'}," + " {'name':'price','type':'DOUBLE'}," + " {'name':'volume','type':'INT'}," + " {'name':'max','type':'DOUBLE'}," + " {'name':'min','type':'Double'}" + " ]" + "}"); Assert.assertEquals(id1, id2); // In this case correlation data is null dataPublisher.publish( id1, new Object[] {"127.0.0.1"}, null, new Object[] {"IBM", 96.8, 300, 120.6, 70.4}); dataPublisher.stop(); testServer.stop(); }
public void testSendingTwoDifferentStreamDefinitionsWithSameStreamId() throws MalformedURLException, AuthenticationException, TransportException, AgentException, UndefinedEventTypeException, InterruptedException, DataBridgeException, MalformedStreamDefinitionException, StreamDefinitionException, DifferentStreamDefinitionAlreadyDefinedException { TestServer testServer = new TestServer(); testServer.start(7617); KeyStoreUtil.setTrustStoreParams(); Thread.sleep(2000); // according to the convention the authentication port will be 7611+100= 7711 and its host will // be the same DataPublisher dataPublisher = new DataPublisher("tcp://localhost:7617", "admin", "admin"); dataPublisher.defineStream( "{" + " 'name':'org.wso2.esb.MediatorStatistics3'," + " 'version':'2.3.0'," + " 'nickName': 'Stock Quote Information'," + " 'description': 'Some Desc'," + " 'tags':['foo', 'bar']," + " 'metaData':[" + " {'name':'ipAdd','type':'STRING'}" + " ]," + " 'payloadData':[" + " {'name':'symbol','type':'STRING'}," + " {'name':'price','type':'DOUBLE'}," + " {'name':'volume','type':'INT'}," + " {'name':'max','type':'DOUBLE'}," + " {'name':'min','type':'Double'}" + " ]" + "}"); Boolean exceptionOccurred = false; try { dataPublisher.defineStream( "{" + " 'name':'org.wso2.esb.MediatorStatistics3'," + " 'version':'2.3.0'," + " 'nickName': 'Stock Quote Information'," + " 'description': 'Some Desc'," + " 'tags':['foo', 'bar']," + " 'metaData':[" + " {'name':'ipAdd','type':'STRING'}" + " ]," + " 'payloadData':[" + " {'name':'symbol','type':'STRING'}," + " {'name':'price','type':'DOUBLE'}," + " {'name':'volume','type':'INT'}," + " {'name':'min','type':'Double'}" + " ]" + "}"); } catch (DifferentStreamDefinitionAlreadyDefinedException e) { exceptionOccurred = true; } Assert.assertTrue(exceptionOccurred); dataPublisher.stop(); testServer.stop(); }
@Before public void before() throws Exception { DateFormat df = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss zzz", Locale.ENGLISH); Date lastModifiedDate = df.parse(LAST_MODIFIED_DATE_MATCH); RestResource.setLastModifiedDate(lastModifiedDate); client = new DefaultHttpClient(); server = new TestServer(); server.start(); }
@Override protected void tearDown() { notFinished = false; try { serverThread.join(); } catch (InterruptedException e) { throw new RuntimeException(e); } try { clientThread.join(); } catch (InterruptedException e) { throw new RuntimeException(e); } // The server must have completed without an exception. if (server.getException() != null) { throw new RuntimeException(server.getException()); } // The client must have completed without an exception. if (client.getException() != null) { throw new RuntimeException(client.getException()); } }
/** Executes a block of code in a running server, with a test browser. */ public static void running( TestServer server, WebDriver webDriver, final Consumer<TestBrowser> block) { synchronized (PlayRunners$.MODULE$.mutex()) { TestBrowser browser = null; TestServer startedServer = null; try { start(server); startedServer = server; browser = testBrowser(webDriver, server.port()); block.accept(browser); } finally { if (browser != null) { browser.quit(); } if (startedServer != null) { stop(startedServer); } } } }
private HttpResponse execute( HttpMethodEnum method, String path, HashMap<String, String> headers) { try { URI uri = URI.create(server.getEndpoint() + path); HttpResponse response; HttpRequestBase hrb; switch (method) { case GET: hrb = new HttpGet(uri); break; case PUT: hrb = new HttpPut(uri); break; case POST: hrb = new HttpPost(uri); break; case PATCH: hrb = new HttpPatch(uri); break; // case Merge: // hrb = new HttpMerge(uri); // break; case DELETE: hrb = new HttpDelete(uri); break; default: throw new RuntimeException("Method unsupported: " + method); } if (null != headers) { for (String header : headers.keySet()) hrb.setHeader(header, headers.get(header)); } response = client.execute(hrb); hrb.reset(); return response; } catch (Exception e) { throw new RuntimeException(e); } }
@After public void tearDown() throws Exception { server.stop(); }
@Before public void setUp() throws Exception { server.start(); }
/** Stops a Test server. */ public static void stop(TestServer server) { server.stop(); }
/** Starts a Test server. */ public static void start(TestServer server) { server.start(); }
@After public void after() { server.stop(); }
public static void main(String[] args) { Logger log = new Logger(1000, true, 2, true, "TesterJosh.log", "Log"); int passDelay = 0; log.resetLog(); if (args.length != 3) { log.log( 1, "Must have 3 args to run.\n USAGE: java testMultipleConfigs numConfigs passesPerconfig"); } int numConfigs = 12; int passesPerconfig = 5; int testMultipleConfigs = 1; try { testMultipleConfigs = Integer.parseInt(args[0]); numConfigs = Integer.parseInt(args[1]); passesPerconfig = Integer.parseInt(args[2]); } catch (Exception e) { log.log(1, "One of the args is not valid. Used defaults."); } int[][] testConfigs = { {100, 1, 1, 0}, {100, 2, 1, 0}, {100, 4, 1, 0}, {100, 10, 1, 0}, {100, 10, 1, 0}, {100, 10, 0, 0}, {100, 10, 1, 1}, {100, 10, 0, 1}, {100, 10, 0, 1}, {200, 10, 0, 1}, {300, 10, 0, 1}, {400, 10, 0, 1}, {1000, 25, 1, 0}, {1000, 50, 1, 0}, {1000, 75, 1, 0}, {1000, 100, 1, 0}, {1000, 100, 1, 0}, {1000, 100, 0, 0}, {1000, 100, 1, 1}, {1000, 100, 0, 1}, {1000, 100, 0, 1}, {2000, 100, 0, 1}, {3000, 100, 0, 1}, {4000, 100, 0, 1} }; long start = System.currentTimeMillis(); int cons = 0; if (testMultipleConfigs > 0 ? true : false) { for (int i = 0; i < numConfigs; i++) { TestServer.testConfiguration( passesPerconfig, passDelay, testConfigs[i][0], testConfigs[i][1], testConfigs[i][2], testConfigs[i][3], log); cons += (passesPerconfig * (testConfigs[i][0])); } } else { TestServer.testConfiguration( passesPerconfig, passDelay, testConfigs[numConfigs - 1][0], testConfigs[numConfigs - 1][1], testConfigs[numConfigs - 1][2], testConfigs[numConfigs - 1][3], log); cons += (passesPerconfig * (testConfigs[numConfigs - 1][0])); } long end = System.currentTimeMillis(); start += numConfigs * passesPerconfig * passDelay; float timeTaken = end - start; log.log(1, "Total Time for all Configurations: " + String.valueOf(timeTaken / 1000) + " Secs."); log.log(1, "Total Connections Attempted:" + cons); log.flush(); }