private void uploadResourcesToConfigRegistry() throws Exception { ResourceAdminServiceClient resourceAdminServiceStub = new ResourceAdminServiceClient( context.getContextUrls().getBackEndUrl(), getSessionCookie()); resourceAdminServiceStub.deleteResource("/_system/config/sequence"); resourceAdminServiceStub.addCollection( "/_system/config/", "sequence", "", "Contains test sequence files"); resourceAdminServiceStub.addResource( "/_system/config/sequence/out_sequence.xml", "application/vnd.wso2.sequence", "application/vnd.wso2.sequence files", new DataHandler( new URL( "file:///" + getESBResourceLocation() + "/proxyconfig/proxy/utils/out_sequence.xml"))); Thread.sleep(2000); resourceAdminServiceStub.addResource( "/_system/config/sequence/fault_sequence.xml", "application/vnd.wso2.sequence", "application/vnd.wso2.sequence files", new DataHandler( new URL( "file:///" + getESBResourceLocation() + "/proxyconfig/proxy/utils/fault_sequence.xml"))); Thread.sleep(1000); }
@Override public void run() { try { final MessageSender sender = msm.acquireSender(); Thread.sleep(rnd.nextInt(THREAD_SLEEP_MILLIS)); msm.releaseSender(sender); counter.decrementAndGet(); } catch (final Throwable t) { threads.put(Thread.currentThread(), t); } }
/** * Tests update of session expiration in memcached (like {@link * #testExpirationOfSessionsInMemcachedIfBackupWasSkippedSimple()}) but for the scenario where * many readonly requests occur: in this case, we cannot just use <em>maxInactiveInterval - * secondsSinceLastBackup</em> (in {@link MemcachedSessionService#updateExpirationInMemcached}) to * determine if an expiration update is required, but we must use the last expiration time sent to * memcached. * * @throws Exception if something goes wrong with the http communication with tomcat */ @Test(enabled = true, dataProviderClass = TestUtils.class, dataProvider = STICKYNESS_PROVIDER) public void testExpirationOfSessionsInMemcachedIfBackupWasSkippedManyReadonlyRequests( final SessionAffinityMode stickyness) throws Exception { final SessionManager manager = _tomcat1.getManager(); setStickyness(stickyness); // set to 1 sec above (in setup), default is 10 seconds final int delay = manager.getContainer().getBackgroundProcessorDelay(); manager.setMaxInactiveInterval(delay * 4); final String sessionId1 = makeRequest(_httpClient, _portTomcat1, null); assertNotNull(sessionId1, "No session created."); assertWaitingWithProxy(Predicates.<MemcachedClientIF>notNull(), 200l, _memcached) .get(sessionId1); /* after 3 seconds make another request without changing the session, so that * it's not sent to memcached */ Thread.sleep(TimeUnit.SECONDS.toMillis(delay * 3)); assertEquals( makeRequest(_httpClient, _portTomcat1, sessionId1), sessionId1, "SessionId should be the same"); assertNotNull(_memcached.get(sessionId1), "Session should still exist in memcached."); /* after another 3 seconds make another request without changing the session */ Thread.sleep(TimeUnit.SECONDS.toMillis(delay * 3)); assertEquals( makeRequest(_httpClient, _portTomcat1, sessionId1), sessionId1, "SessionId should be the same"); assertNotNull(_memcached.get(sessionId1), "Session should still exist in memcached."); /* after another nearly 4 seconds (maxInactiveInterval) check that the session is still alive in memcached, * this would have been expired without an updated expiration */ Thread.sleep(TimeUnit.SECONDS.toMillis(manager.getMaxInactiveInterval()) - 500); assertNotNull(_memcached.get(sessionId1), "Session should still exist in memcached."); /* after another second in sticky mode (more than 4 seconds since the last request), or an two times the * maxInactiveInterval in non-sticky mode (we must keep sessions in memcached with double expirationtime) * the session must be expired in memcached */ Thread.sleep(TimeUnit.SECONDS.toMillis(delay) + 500); assertNotSame( makeRequest(_httpClient, _portTomcat1, sessionId1), sessionId1, "The sessionId should have changed due to expired sessin"); }
/** * Test for issue #60 (Add possibility to disable msm at runtime): start msm disabled and * afterwards enable */ @Test(enabled = true) public void testStartMsmDisabled() throws Exception { // shutdown our server and our client _memcached.shutdown(); _daemon.stop(); // start a new tomcat with msm initially disabled _tomcat1.stop(); Thread.sleep(500); final String memcachedNodes = _memcachedNodeId + ":localhost:" + _memcachedPort; _tomcat1 = getTestUtils() .tomcatBuilder() .port(_portTomcat1) .memcachedNodes(memcachedNodes) .sticky(true) .enabled(false) .jvmRoute("app1") .buildAndStart(); LOG.info("Waiting, check logs to see if the client causes any 'Connection refused' logging..."); Thread.sleep(1000); // some basic tests for session functionality checkSessionFunctionalityWithMsmDisabled(); // start memcached, client and reenable msm _daemon.start(); _memcached = createMemcachedClient(memcachedNodes, new InetSocketAddress("localhost", _memcachedPort)); _tomcat1.getManager().setEnabled(true); // Wait a little bit, so that msm's memcached client can connect and is ready when test starts Thread.sleep(100); // memcached based stuff should work again final String sessionId1 = makeRequest(_httpClient, _portTomcat1, null); assertNotNull(sessionId1, "No session created."); assertNotNull( new SessionIdFormat().extractMemcachedId(sessionId1), "memcached node id missing with msm switched to enabled"); Thread.sleep(50); assertNotNull(_memcached.get(sessionId1), "Session not available in memcached."); waitForSessionExpiration(true); assertNull(_memcached.get(sessionId1), "Expired session still existing in memcached"); }
/** * Test for issue #49: Sessions not associated with a memcached node don't get associated as soon * as a memcached is available * * @throws InterruptedException * @throws IOException * @throws TimeoutException * @throws ExecutionException */ @Test(enabled = true) public void testNotAssociatedSessionGetsAssociatedIssue49() throws InterruptedException, IOException, ExecutionException, TimeoutException { _daemon.stop(); final SessionManager manager = _tomcat1.getManager(); manager.setMaxInactiveInterval(5); manager.setSticky(true); final SessionIdFormat sessionIdFormat = new SessionIdFormat(); final Session session = manager.createSession(null); assertNull(sessionIdFormat.extractMemcachedId(session.getId())); _daemon.start(); // Wait so that the daemon will be available and the client can reconnect (async get didn't do // the trick) Thread.sleep(4000); final String newSessionId = manager.getMemcachedSessionService().changeSessionIdOnMemcachedFailover(session.getId()); assertNotNull(newSessionId); assertEquals(newSessionId, session.getId()); assertEquals(sessionIdFormat.extractMemcachedId(newSessionId), _memcachedNodeId); }
@Test public void testAsyncLateListener() throws Exception { ListenableFuture<String> getFuture; final CountDownLatch latch = new CountDownLatch(1); try (DelayedMap.AsyncClient client = createClient(DelayedMap.AsyncClient.class, syncServer).get()) { getFuture = client.getValueSlowly(250, TimeUnit.MILLISECONDS, "testKey"); // Sleep first, to test the case where the callback is executed immediately Thread.sleep(500); Futures.addCallback( getFuture, new FutureCallback<String>() { @Override public void onSuccess(String result) { latch.countDown(); } @Override public void onFailure(Throwable t) { fail("Async call to getValueSlowly failed", t); } }); // Because of the sleep above, the latch should already be open // (because the callback is added on this thread and the default callback // executor runs callbacks on the same thread, this shouldn't even be a race). assertTrue(latch.await(0, TimeUnit.MILLISECONDS)); } }
@Test(groups = "standalone") public void testObserveMultiple() { final TestSubscriber<Response> tester = new TestSubscriber<>(); try (AsyncHttpClient client = asyncHttpClient()) { Observable<Response> o1 = AsyncHttpObservable.observe(() -> client.prepareGet("http://gatling.io")); Observable<Response> o2 = AsyncHttpObservable.observe( () -> client.prepareGet("http://www.wisc.edu").setFollowRedirect(true)); Observable<Response> o3 = AsyncHttpObservable.observe( () -> client.prepareGet("http://www.umn.edu").setFollowRedirect(true)); Observable<Response> all = Observable.merge(o1, o2, o3); all.subscribe(tester); tester.awaitTerminalEvent(); tester.assertTerminalEvent(); tester.assertCompleted(); tester.assertNoErrors(); List<Response> responses = tester.getOnNextEvents(); assertNotNull(responses); assertEquals(responses.size(), 3); for (Response response : responses) { assertEquals(response.getStatusCode(), 200); } } catch (Exception e) { Thread.currentThread().interrupt(); } }
@Test public void testGetDurationWithUnit() throws Exception { testStopwatch.start(); Thread.sleep(10); testStopwatch.stop(); assertTrue(testStopwatch.getDuration() > 12); }
/** * Click and browse genre link * * @throws InterruptedException */ public void browseGenre() throws InterruptedException { epor.browseGenre.click(); List<WebElement> genres = driver.findElements(By.className("ODSearch_genreBox")); System.out.print("Genres: "); for (WebElement genre : genres) { System.out.print(genre.getText() + "; "); genre.click(); pf.captureScreenShot(driver, genre.getText()); Thread.sleep(1500); } System.out.print("\n"); assertEquals(7, genres.size()); epor.browseGenreComedy.click(); Thread.sleep(1500); }
/** * Click and browse genre link * * @throws InterruptedException */ public void browseChannel() throws InterruptedException { epor.browseChannel.click(); List<WebElement> channels = driver.findElements(By.className("ODSearch_Channel")); System.out.print("Channel: "); for (WebElement channel : channels) { System.out.print(channel.getText() + "; "); channel.click(); pf.captureScreenShot(driver, channel.getText()); Thread.sleep(1500); } System.out.print("\n"); assertEquals(2, channels.size()); epor.browseChannelThree.click(); Thread.sleep(1500); }
/** * Test prepared query. * * @param qCom the q com * @throws Exception the exception */ @Test(dataProvider = "queryCommands") public void preparedQuery(LensQueryCommands qCom) throws Exception { long submitTime = System.currentTimeMillis(); String sql = "cube select id, name from test_dim"; String result = qCom.getAllPreparedQueries("testPreparedName", "all", submitTime, Long.MAX_VALUE); assertEquals(result, "No prepared queries"); final String qh = qCom.prepare(sql, "testPreparedName"); result = qCom.getAllPreparedQueries( "testPreparedName", "all", submitTime, System.currentTimeMillis()); assertEquals(qh, result); result = qCom.getPreparedStatus(qh); assertTrue(result.contains("User query:cube select id, name from test_dim")); assertTrue(result.contains(qh)); result = qCom.executePreparedQuery(qh, false, "testPrepQuery1"); log.warn("XXXXXX Prepared query sync result is " + result); assertTrue(result.contains("1\tfirst")); String handle = qCom.executePreparedQuery(qh, true, "testPrepQuery2"); log.debug("Perpared query handle is " + handle); while (!qCom.getClient().getQueryStatus(handle).finished()) { Thread.sleep(5000); } String status = qCom.getStatus(handle); log.debug("Prepared Query Status is " + status); assertTrue(status.contains("Status : SUCCESSFUL")); result = qCom.getQueryResults(handle, null, true); log.debug("Prepared Query Result is " + result); assertTrue(result.contains("1\tfirst")); // Fetch again. result = qCom.getQueryResults(handle, null, true); log.debug("Prepared Query Result is " + result); assertTrue(result.contains("1\tfirst")); result = qCom.destroyPreparedQuery(qh); log.debug("destroy result is " + result); assertEquals("Successfully destroyed " + qh, result); result = qCom.getAllPreparedQueries("testPreparedName", "all", submitTime, Long.MAX_VALUE); assertEquals(result, "No prepared queries"); final String qh2 = qCom.explainAndPrepare(sql, "testPrepQuery3"); assertTrue(qh2.contains(explainPlan)); String handles = qCom.getAllPreparedQueries("testPrepQuery3", "all", -1, Long.MAX_VALUE); assertFalse(handles.contains("No prepared queries"), handles); String handles2 = qCom.getAllPreparedQueries("testPrepQuery3", "all", -1, submitTime - 1); assertFalse(handles2.contains(qh), handles2); result = qCom.destroyPreparedQuery(handles); assertEquals("Successfully destroyed " + handles, result); }
@Test public void testReset() throws Exception { testStopwatch.start(); Thread.sleep(10); testStopwatch.stop(); assertTrue(testStopwatch.getDuration() > 0); testStopwatch.reset(); assertTrue(testStopwatch.getDuration() == 0); }
@Test(dependsOnMethods = "checkChangeCategoryName", groups = "Enterprise-only", timeOut = 400000) public void checkDeleteCategory() throws Exception { CategoryManagerPage categoryManagerPage = drone.getCurrentPage().render(); int categoryCount = categoryManagerPage.getCategoriesCount(); categoryManagerPage.deleteCategory(renameCategoryName); Thread.sleep(solrWaitTime); // wait solr drone.refresh(); assertFalse(categoryManagerPage.isCategoryPresent(renameCategoryName)); assertTrue(categoryCount - 2 == categoryManagerPage.getCategoriesCount()); }
@Test(dependsOnMethods = "checkOpenSubCategory", groups = "Enterprise-only", timeOut = 400000) public void checkChangeCategoryName() throws Exception { CategoryManagerPage categoryManagerPage = drone.getCurrentPage().render(); categoryManagerPage.editCategory(categoryName, renameCategoryName); Thread.sleep(solrWaitTime); // wait solr drone.refresh(); assertTrue(categoryManagerPage.isCategoryPresent(renameCategoryName)); categoryManagerPage.openSubCategoryList(renameCategoryName); assertTrue(categoryManagerPage.isCategoryPresent(subCategoryName)); }
private void assertEventuallyEquals(List<?> actual, List<?> expected, long timeout) throws InterruptedException { long startTime = System.currentTimeMillis(); while (System.currentTimeMillis() < startTime + timeout) { if (expected.equals(actual)) { return; // success } Thread.sleep(timeout / 100L); } assertEquals(actual, expected, "After waiting " + timeout + "ms"); }
@Test(enabled = true, dataProviderClass = TestUtils.class, dataProvider = STICKYNESS_PROVIDER) public void testSessionAvailableInMemcached(final SessionAffinityMode sessionAffinity) throws IOException, InterruptedException, HttpException { setStickyness(sessionAffinity); final String sessionId1 = makeRequest(_httpClient, _portTomcat1, null); assertNotNull(sessionId1, "No session created."); Thread.sleep(50); assertNotNull(_memcached.get(sessionId1), "Session not available in memcached."); }
@Test public void testTrim() throws Exception { ReplicationServer replicationServer = null; JEReplicaDB replicaDB = null; try { TestCaseUtils.startServer(); replicationServer = configureReplicationServer(100, 5000); replicaDB = newReplicaDB(replicationServer); CSN[] csns = generateCSNs(1, 0, 5); replicaDB.add(new DeleteMsg(TEST_ROOT_DN, csns[0], "uid")); replicaDB.add(new DeleteMsg(TEST_ROOT_DN, csns[1], "uid")); replicaDB.add(new DeleteMsg(TEST_ROOT_DN, csns[2], "uid")); DeleteMsg update4 = new DeleteMsg(TEST_ROOT_DN, csns[3], "uid"); // -- // Iterator tests with changes persisted assertFoundInOrder(replicaDB, csns[0], csns[1], csns[2]); assertNotFound(replicaDB, csns[4], AFTER_MATCHING_KEY); assertEquals(replicaDB.getOldestCSN(), csns[0]); assertEquals(replicaDB.getNewestCSN(), csns[2]); // -- // Cursor tests with changes persisted replicaDB.add(update4); assertFoundInOrder(replicaDB, csns[0], csns[1], csns[2], csns[3]); // Test cursor from existing CSN assertFoundInOrder(replicaDB, csns[2], csns[3]); assertFoundInOrder(replicaDB, csns[3]); assertNotFound(replicaDB, csns[4], AFTER_MATCHING_KEY); replicaDB.purgeUpTo(new CSN(Long.MAX_VALUE, 0, 0)); int count = 0; boolean purgeSucceeded = false; final CSN expectedNewestCSN = csns[3]; do { Thread.sleep(10); final CSN oldestCSN = replicaDB.getOldestCSN(); final CSN newestCSN = replicaDB.getNewestCSN(); purgeSucceeded = oldestCSN.equals(expectedNewestCSN) && newestCSN.equals(expectedNewestCSN); count++; } while (!purgeSucceeded && count < 100); assertTrue(purgeSucceeded); } finally { shutdown(replicaDB); remove(replicationServer); } }
private void waitForSessionExpiration(final boolean sticky) throws InterruptedException { final SessionManager manager = _tomcat1.getManager(); assertEquals(manager.getMemcachedSessionService().isSticky(), sticky); final Container container = manager.getContainer(); final long timeout = TimeUnit.SECONDS.toMillis( sticky ? container.getBackgroundProcessorDelay() + manager.getMaxInactiveInterval() : 2 * manager.getMaxInactiveInterval()) + 1000; Thread.sleep(timeout); }
private void clearUploadedResource() throws InterruptedException, ResourceAdminServiceExceptionException, RemoteException, XPathExpressionException { ResourceAdminServiceClient resourceAdminServiceStub = new ResourceAdminServiceClient( context.getContextUrls().getBackEndUrl(), getSessionCookie()); resourceAdminServiceStub.deleteResource("/_system/config/sequence"); Thread.sleep(1000); }
/** * Tests, that for a session that was not sent to memcached (because it's attributes were not * modified), the expiration is updated so that they don't expire in memcached before they expire * in tomcat. * * @throws Exception if something goes wrong with the http communication with tomcat */ @Test(enabled = true, dataProviderClass = TestUtils.class, dataProvider = STICKYNESS_PROVIDER) public void testExpirationOfSessionsInMemcachedIfBackupWasSkippedSimple( final SessionAffinityMode stickyness) throws Exception { final SessionManager manager = _tomcat1.getManager(); setStickyness(stickyness); // set to 1 sec above (in setup), default is 10 seconds final int delay = manager.getContainer().getBackgroundProcessorDelay(); manager.setMaxInactiveInterval(delay * 4); final String sessionId1 = makeRequest(_httpClient, _portTomcat1, null); assertNotNull(sessionId1, "No session created."); assertNotNull(_memcached.get(sessionId1), "Session not available in memcached."); /* after 2 seconds make another request without changing the session, so that * it's not sent to memcached */ Thread.sleep(TimeUnit.SECONDS.toMillis(delay * 2)); assertEquals( makeRequest(_httpClient, _portTomcat1, sessionId1), sessionId1, "SessionId should be the same"); /* after another 3 seconds check that the session is still alive in memcached, * this would have been expired without an updated expiration */ Thread.sleep(TimeUnit.SECONDS.toMillis(delay * 3)); assertNotNull(_memcached.get(sessionId1), "Session should still exist in memcached."); /* after another >1 second (4 seconds since the last request) * the session must be expired in memcached */ Thread.sleep( TimeUnit.SECONDS.toMillis(delay) + 500); // +1000 just to be sure that we're >4 secs assertNotSame( makeRequest(_httpClient, _portTomcat1, sessionId1), sessionId1, "The sessionId should have changed due to expired sessin"); }
/** * Verify Kid's contents * * @throws InterruptedException */ public void browseGenreKid() throws InterruptedException { epor.browseGenreKids.click(); List<WebElement> genreKid = driver.findElements(By.className("Kids")); System.out.print("Kid: "); for (WebElement kid : genreKid) { System.out.print(kid.getText() + "; "); } System.out.print("\n"); assertEquals(10, genreKid.size()); Thread.sleep(1500); }
/** * Verify Genre's contents * * @throws InterruptedException */ public void browseGenreSport() throws InterruptedException { epor.browseGenreSport.click(); List<WebElement> genreSport = driver.findElements(By.className("Sport")); System.out.print("Sport: "); for (WebElement sport : genreSport) { System.out.print(sport.getText() + "; "); } System.out.print("\n"); assertEquals(4, genreSport.size()); Thread.sleep(1500); }
/** * Verify Reality's contents * * @throws InterruptedException */ public void browseGenreReality() throws InterruptedException { epor.browseGenreReality.click(); List<WebElement> genreReality = driver.findElements(By.className("Reality")); System.out.print("Reality: "); for (WebElement reality : genreReality) { System.out.print(reality.getText() + "; "); } System.out.print("\n"); assertEquals(19, genreReality.size()); Thread.sleep(1500); }
/** * Verify News' contents * * @throws InterruptedException */ public void browseGenreNews() throws InterruptedException { epor.browseGenreNews.click(); List<WebElement> genreNews = driver.findElements(By.className("NewsCurrentAffairs")); System.out.print("News: "); for (WebElement news : genreNews) { System.out.print(news.getText() + "; "); } System.out.print("\n"); assertEquals(3, genreNews.size()); Thread.sleep(1500); }
/** * Verify W's contents * * @throws InterruptedException */ public void browseTitleW() throws InterruptedException { epor.browseTitleW.click(); List<WebElement> titleWContents = driver.findElements(By.className("StartW")); System.out.print("W's contents: "); for (WebElement wContent : titleWContents) { System.out.print(wContent.getText() + "; "); } System.out.print("\n"); assertEquals(1, titleWContents.size()); Thread.sleep(1000); }
/** * Verify Three's contents * * @throws InterruptedException */ public void browseChannelThree() throws InterruptedException { epor.browseChannelThree2.click(); List<WebElement> channelThree = driver.findElements(By.className("tv3")); System.out.print("TV Three: "); for (WebElement three : channelThree) { System.out.print(three.getText() + "; "); } System.out.print("\n"); assertEquals(42, channelThree.size()); Thread.sleep(1500); }
/** * Verify Four's contents * * @throws InterruptedException */ public void browseChannelFour() throws InterruptedException { epor.browseChannelFour.click(); List<WebElement> channelFour = driver.findElements(By.className("four")); System.out.print("Four: "); for (WebElement four : channelFour) { System.out.print(four.getText() + "; "); } System.out.print("\n"); assertEquals(19, channelFour.size()); Thread.sleep(1500); }
public void handle( String s, Request r, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { try { Thread.sleep(210L); } catch (InterruptedException e) { } response.setContentType("text/plain"); response.setStatus(400); OutputStream out = response.getOutputStream(); out.write(BAD_REQUEST_STR.getBytes(UTF_8)); out.flush(); }
/** * Verify Drama's contents * * @throws InterruptedException */ public void browseGenreDrama() throws InterruptedException { epor.browseGenreDrama.click(); List<WebElement> genreDrama = driver.findElements(By.className("Drama")); System.out.print("Drama: "); for (WebElement drama : genreDrama) { System.out.print(drama.getText() + "; "); } System.out.print("\n"); assertEquals(6, genreDrama.size()); Thread.sleep(1500); }
private void setStickyness(final SessionAffinityMode sessionAffinity) { if (!sessionAffinity.isSticky()) { _tomcat1.getEngine().setJvmRoute(null); } final SessionManager manager = _tomcat1.getManager(); manager.setSticky(sessionAffinity.isSticky()); try { waitForReconnect(manager.getMemcachedSessionService().getMemcached(), 1, 500); } catch (final InterruptedException e) { Thread.currentThread().interrupt(); throw new RuntimeException(e); } }