[jboss-cvs] JBossAS SVN: r108797 - branches/JBPAPP_5_1_datagrid/testsuite/src/main/org/jboss/test/cluster/datagrid/test.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Fri Oct 22 11:16:19 EDT 2010


Author: mlinhard
Date: 2010-10-22 11:16:19 -0400 (Fri, 22 Oct 2010)
New Revision: 108797

Modified:
   branches/JBPAPP_5_1_datagrid/testsuite/src/main/org/jboss/test/cluster/datagrid/test/RESTClientTestCase.java
Log:
added some testcases, changed TestCase configuration

Modified: branches/JBPAPP_5_1_datagrid/testsuite/src/main/org/jboss/test/cluster/datagrid/test/RESTClientTestCase.java
===================================================================
--- branches/JBPAPP_5_1_datagrid/testsuite/src/main/org/jboss/test/cluster/datagrid/test/RESTClientTestCase.java	2010-10-22 14:41:57 UTC (rev 108796)
+++ branches/JBPAPP_5_1_datagrid/testsuite/src/main/org/jboss/test/cluster/datagrid/test/RESTClientTestCase.java	2010-10-22 15:16:19 UTC (rev 108797)
@@ -54,10 +54,10 @@
 	public RESTClientTestCase(String name) {
 		super(name);
 	}
-
+	private String[] httpUrls;
 	private HttpClient client;
-	private static final String INFINISPAN_REST_PREFIX = "http://localhost:8080/infinispan-server-rest/rest";
-	private static final String FULL_PATH = INFINISPAN_REST_PREFIX + "/___defaultcache";
+	private String infinispanRestPrefix;
+	private String fullPath;
 	private static final String DATE_PATTERN_RFC1123 = "EEE, dd MMM yyyy HH:mm:ss zzz";
 
 	private static class TestSerializable implements Serializable {
@@ -76,49 +76,68 @@
 	@Override
 	protected void setUp() throws Exception {
 		super.setUp();
+		httpUrls = getHttpURLs();
 		client = new HttpClient();
+		infinispanRestPrefix = httpUrls[0] + "/infinispan-server-rest/rest"; 
+		fullPath = infinispanRestPrefix + "/___defaultcache";
 	}
 	
 	@Override
 	protected void tearDown() throws Exception {
 		super.tearDown();
-		delete(FULL_PATH + "/testBasicOperation");
-		delete(FULL_PATH + "/testGet");
-		delete(FULL_PATH + "/testHead");
-		delete(FULL_PATH + "/testPostDuplicate");
-		delete(FULL_PATH + "/testPutDataWithTimeToLive");
-		delete(FULL_PATH + "/testRemoveEntry");
-		delete(FULL_PATH + "/testWipeCacheBucket");
-		delete(FULL_PATH + "/testWipeCacheBucket2");
-		delete(FULL_PATH + "/testAsyncAddRemove");
-		delete(FULL_PATH + "/testPutUnknownClass");
-		delete(FULL_PATH + "/testETagChanges");
-		delete(FULL_PATH + "/testIfModifiedSince");
-		delete(FULL_PATH + "/testIfUnmodifiedSince");
-		delete(FULL_PATH + "/testIfNoneMatch");
-		delete(FULL_PATH + "/testIfMatch");
+		delete(fullPath + "/testBasicOperation");
+		delete(fullPath + "/testBasicClusteredOperation");
+		delete(fullPath + "/testGet");
+		delete(fullPath + "/testHead");
+		delete(fullPath + "/testPostDuplicate");
+		delete(fullPath + "/testPutDataWithTimeToLive");
+		delete(fullPath + "/testPutDataWithMaxIdleTime");
+		delete(fullPath + "/testPutDataTTLMaxIdleCombo1");
+		delete(fullPath + "/testPutDataTTLMaxIdleCombo2");
+		delete(fullPath + "/testPutDataWithTimeToLiveAsync");
+		delete(fullPath + "/testPutDataWithMaxIdleTimeAsync");
+		delete(fullPath + "/testPutDataTTLMaxIdleCombo1Async");
+		delete(fullPath + "/testPutDataTTLMaxIdleCombo2Async");
+		delete(fullPath + "/testRemoveEntry");
+		delete(fullPath + "/testWipeCacheBucket");
+		delete(fullPath + "/testWipeCacheBucket2");
+		delete(fullPath + "/testAsyncAddRemove");
+		delete(fullPath + "/testPutUnknownClass");
+		delete(fullPath + "/testETagChanges");
+		delete(fullPath + "/testIfModifiedSince");
+		delete(fullPath + "/testIfUnmodifiedSince");
+		delete(fullPath + "/testIfNoneMatch");
+		delete(fullPath + "/testIfMatch");
 	}
 
 	public void testCacheIsCleanForTesting() throws Exception {
-		head(FULL_PATH + "/testBasicOperation", HttpServletResponse.SC_NOT_FOUND);
-		head(FULL_PATH + "/testGet", HttpServletResponse.SC_NOT_FOUND);
-		head(FULL_PATH + "/testHead", HttpServletResponse.SC_NOT_FOUND);
-		head(FULL_PATH + "/testPostDuplicate", HttpServletResponse.SC_NOT_FOUND);
-		head(FULL_PATH + "/testPutDataWithTimeToLive", HttpServletResponse.SC_NOT_FOUND);
-		head(FULL_PATH + "/testRemoveEntry", HttpServletResponse.SC_NOT_FOUND);
-		head(FULL_PATH + "/testWipeCacheBucket", HttpServletResponse.SC_NOT_FOUND);
-		head(FULL_PATH + "/testWipeCacheBucket2", HttpServletResponse.SC_NOT_FOUND);
-		head(FULL_PATH + "/testAsyncAddRemove", HttpServletResponse.SC_NOT_FOUND);
-		head(FULL_PATH + "/testPutUnknownClass", HttpServletResponse.SC_NOT_FOUND);
-		head(FULL_PATH + "/testETagChanges", HttpServletResponse.SC_NOT_FOUND);
-		head(FULL_PATH + "/testIfModifiedSince", HttpServletResponse.SC_NOT_FOUND);
-		head(FULL_PATH + "/testIfUnmodifiedSince", HttpServletResponse.SC_NOT_FOUND);
-		head(FULL_PATH + "/testIfNoneMatch", HttpServletResponse.SC_NOT_FOUND);
-		head(FULL_PATH + "/testIfMatch", HttpServletResponse.SC_NOT_FOUND);
+		head(fullPath + "/testBasicOperation", HttpServletResponse.SC_NOT_FOUND);
+		head(fullPath + "/testBasicClusteredOperation", HttpServletResponse.SC_NOT_FOUND);
+		head(fullPath + "/testGet", HttpServletResponse.SC_NOT_FOUND);
+		head(fullPath + "/testHead", HttpServletResponse.SC_NOT_FOUND);
+		head(fullPath + "/testPostDuplicate", HttpServletResponse.SC_NOT_FOUND);
+		head(fullPath + "/testPutDataWithTimeToLive", HttpServletResponse.SC_NOT_FOUND);
+		head(fullPath + "/testPutDataWithMaxIdleTime", HttpServletResponse.SC_NOT_FOUND);
+		head(fullPath + "/testPutDataTTLMaxIdleCombo1", HttpServletResponse.SC_NOT_FOUND);
+		head(fullPath + "/testPutDataTTLMaxIdleCombo2", HttpServletResponse.SC_NOT_FOUND);
+		head(fullPath + "/testPutDataWithTimeToLiveAsync", HttpServletResponse.SC_NOT_FOUND);
+		head(fullPath + "/testPutDataWithMaxIdleTimeAsync", HttpServletResponse.SC_NOT_FOUND);
+		head(fullPath + "/testPutDataTTLMaxIdleCombo1Async", HttpServletResponse.SC_NOT_FOUND);
+		head(fullPath + "/testPutDataTTLMaxIdleCombo2Async", HttpServletResponse.SC_NOT_FOUND);
+		head(fullPath + "/testRemoveEntry", HttpServletResponse.SC_NOT_FOUND);
+		head(fullPath + "/testWipeCacheBucket", HttpServletResponse.SC_NOT_FOUND);
+		head(fullPath + "/testWipeCacheBucket2", HttpServletResponse.SC_NOT_FOUND);
+		head(fullPath + "/testAsyncAddRemove", HttpServletResponse.SC_NOT_FOUND);
+		head(fullPath + "/testPutUnknownClass", HttpServletResponse.SC_NOT_FOUND);
+		head(fullPath + "/testETagChanges", HttpServletResponse.SC_NOT_FOUND);
+		head(fullPath + "/testIfModifiedSince", HttpServletResponse.SC_NOT_FOUND);
+		head(fullPath + "/testIfUnmodifiedSince", HttpServletResponse.SC_NOT_FOUND);
+		head(fullPath + "/testIfNoneMatch", HttpServletResponse.SC_NOT_FOUND);
+		head(fullPath + "/testIfMatch", HttpServletResponse.SC_NOT_FOUND);
 	}
 	
 	public void testBasicOperation() throws Exception {
-		String fullPathKey = FULL_PATH + "/testBasicOperation";
+		String fullPathKey = fullPath + "/testBasicOperation";
 		String initialXML = "<hey>ho</hey>";
 		PutMethod insert = put(fullPathKey, initialXML, "application/octet-stream");
 		assertEquals("", insert.getResponseBodyAsString().trim());
@@ -137,7 +156,7 @@
 		client.executeMethod(get);
 		assertEquals(initialXML, get.getResponseBodyAsString());
 
-		DeleteMethod removeAll = new DeleteMethod(FULL_PATH);
+		DeleteMethod removeAll = new DeleteMethod(fullPath);
 		client.executeMethod(removeAll);
 
 		client.executeMethod(get);
@@ -159,13 +178,23 @@
 		TestSerializable ts = (TestSerializable) oin.readObject();
 		assertEquals("CONTENT", ts.getContent());
 	}
+	
+	public void testBasicClusteredOperation() throws Exception {
+		assertEquals(2, httpUrls.length);
+		String fullPathKey1 = fullPath + "/testBasicClusteredOperation";
+		String fullPathKey2 = httpUrls[1] + "/infinispan-server-rest/rest/___defaultcache/testBasicClusteredOperation";
+		put(fullPathKey1, "data", "text/plain");
+		// wait for replication
+		Thread.sleep(1000);
+		assertEquals("data", get(fullPathKey2).getResponseBodyAsString());
+	}
 
 	public void testEmptyGet() throws Exception {
-		get(FULL_PATH + "/nodata", HttpServletResponse.SC_NOT_FOUND);
+		get(fullPath + "/nodata", HttpServletResponse.SC_NOT_FOUND);
 	}
 
 	public void testGet() throws Exception {
-		String fullPathKey = FULL_PATH + "/testGet";
+		String fullPathKey = fullPath + "/testGet";
 		post(fullPathKey, "data", "application/text");
 		GetMethod get = get(fullPathKey);
 		assertNotNull(get.getResponseHeader("ETag").getValue());
@@ -175,7 +204,7 @@
 	}
 
 	public void testHead() throws Exception {
-		String fullPathKey = FULL_PATH + "/testHead";
+		String fullPathKey = fullPath + "/testHead";
 		post(fullPathKey, "data", "application/text");
 		HeadMethod head = head(fullPathKey);
 		assertNotNull(head.getResponseHeader("ETag").getValue());
@@ -185,7 +214,7 @@
 	}
 
 	public void testPostDuplicate() throws Exception {
-		String fullPathKey = FULL_PATH + "/testPostDuplicate";
+		String fullPathKey = fullPath + "/testPostDuplicate";
 		
 		post(fullPathKey, "data", "application/text");
 		// second post, returns 409
@@ -195,23 +224,169 @@
 	}
 
 	public void testPutDataWithTimeToLive() throws Exception {
-		String fullPathKey = FULL_PATH + "/testPutDataWithTimeToLive";
+		String fullPathKey = fullPath + "/testPutDataWithTimeToLive";
 		
 		post(fullPathKey, "data", "application/text", HttpServletResponse.SC_OK, 
 			// headers
 			"Content-Type", "application/text",	
+			"timeToLiveSeconds", "2"	
+		);
+		
+		assertEquals("data", get(fullPathKey).getResponseBodyAsString());
+		Thread.sleep(2100);
+		// should be evicted
+		head(fullPathKey, HttpServletResponse.SC_NOT_FOUND);
+	}
+	
+	// https://jira.jboss.org/browse/JBPAPP-5289
+	public void testPutDataWithMaxIdleTime() throws Exception {
+		String fullPathKey = fullPath + "/testPutDataWithMaxIdleTime";
+		
+		post(fullPathKey, "data", "application/text", HttpServletResponse.SC_OK, 
+			// headers
+			"Content-Type", "application/text",	
+			"maxIdleTimeSeconds", "2"	
+		);
+		
+		assertEquals("data", get(fullPathKey).getResponseBodyAsString());
+		
+		// data is not idle for next 3 seconds
+		for (int i = 1; i < 3; i++) {
+			Thread.sleep(1000);
+			head(fullPathKey);
+		}
+		
+		// idle for 2 seconds
+		Thread.sleep(2100);
+		// should be evicted
+		head(fullPathKey, HttpServletResponse.SC_NOT_FOUND);
+	}
+	
+	public void testPutDataTTLMaxIdleCombo1() throws Exception {
+		String fullPathKey = fullPath + "/testPutDataTTLMaxIdleCombo1";
+		
+		post(fullPathKey, "data", "application/text", HttpServletResponse.SC_OK, 
+			// headers
+			"Content-Type", "application/text",	
+			"timeToLiveSeconds", "10",	
+			"maxIdleTimeSeconds", "2"	
+		);
+		
+		assertEquals("data", get(fullPathKey).getResponseBodyAsString());
+		
+		// data is not idle for next 3 seconds
+		for (int i = 1; i < 3; i++) {
+			Thread.sleep(1000);
+			head(fullPathKey);
+		}
+		
+		// idle for 2 seconds
+		Thread.sleep(2100);
+		// should be evicted
+		head(fullPathKey, HttpServletResponse.SC_NOT_FOUND);
+	}
+	
+	public void testPutDataTTLMaxIdleCombo2() throws Exception {
+		String fullPathKey = fullPath + "/testPutDataTTLMaxIdleCombo2";
+		
+		post(fullPathKey, "data", "application/text", HttpServletResponse.SC_OK, 
+			// headers
+			"Content-Type", "application/text",	
 			"timeToLiveSeconds", "2",	
-			"maxIdleTimeSeconds", "3"	
+			"maxIdleTimeSeconds", "10"	
 		);
 		
 		assertEquals("data", get(fullPathKey).getResponseBodyAsString());
-		Thread.sleep(3000);
+		Thread.sleep(2100);
 		// should be evicted
-		get(fullPathKey, HttpServletResponse.SC_NOT_FOUND);
+		head(fullPathKey, HttpServletResponse.SC_NOT_FOUND);
 	}
+	
+	public void testPutDataWithTimeToLiveAsync() throws Exception {
+		String fullPathKey = fullPath + "/testPutDataWithTimeToLiveAsync";
+		
+		post(fullPathKey, "data", "application/text", HttpServletResponse.SC_OK, 
+			// headers
+			"Content-Type", "application/text",	
+			"timeToLiveSeconds", "2",
+			"performAsync", "true"
+		);
+		
+		assertEquals("data", get(fullPathKey).getResponseBodyAsString());
+		Thread.sleep(2100);
+		// should be evicted
+		head(fullPathKey, HttpServletResponse.SC_NOT_FOUND);
+	}
+	
+	// https://jira.jboss.org/browse/JBPAPP-5289
+	public void testPutDataWithMaxIdleTimeAsync() throws Exception {
+		String fullPathKey = fullPath + "/testPutDataWithMaxIdleTimeAsync";
+		
+		post(fullPathKey, "data", "application/text", HttpServletResponse.SC_OK, 
+			// headers
+			"Content-Type", "application/text",	
+			"maxIdleTimeSeconds", "2",
+			"performAsync", "true"
+		);
+		
+		assertEquals("data", get(fullPathKey).getResponseBodyAsString());
+		
+		// data is not idle for next 3 seconds
+		for (int i = 1; i < 3; i++) {
+			Thread.sleep(1000);
+			head(fullPathKey);
+		}
+		
+		// idle for 2 seconds
+		Thread.sleep(2100);
+		// should be evicted
+		head(fullPathKey, HttpServletResponse.SC_NOT_FOUND);
+	}
+	
+	public void testPutDataTTLMaxIdleCombo1Async() throws Exception {
+		String fullPathKey = fullPath + "/testPutDataTTLMaxIdleCombo1Async";
+		
+		post(fullPathKey, "data", "application/text", HttpServletResponse.SC_OK, 
+			// headers
+			"Content-Type", "application/text",	
+			"timeToLiveSeconds", "10",	
+			"maxIdleTimeSeconds", "2",
+			"performAsync", "true"
+		);
+		
+		assertEquals("data", get(fullPathKey).getResponseBodyAsString());
+		
+		// data is not idle for next 3 seconds
+		for (int i = 1; i < 3; i++) {
+			Thread.sleep(1000);
+			head(fullPathKey);
+		}
+		
+		// idle for 2 seconds
+		Thread.sleep(2100);
+		// should be evicted
+		head(fullPathKey, HttpServletResponse.SC_NOT_FOUND);
+	}
+	
+	public void testPutDataTTLMaxIdleCombo2Async() throws Exception {
+		String fullPathKey = fullPath + "/testPutDataTTLMaxIdleCombo2Async";
+		
+		post(fullPathKey, "data", "application/text", HttpServletResponse.SC_OK, 
+			// headers
+			"Content-Type", "application/text",	
+			"timeToLiveSeconds", "2",	
+			"maxIdleTimeSeconds", "10",
+			"performAsync", "true"
+		);
+		
+		assertEquals("data", get(fullPathKey).getResponseBodyAsString());
+		Thread.sleep(2100);
+		// should be evicted
+		head(fullPathKey, HttpServletResponse.SC_NOT_FOUND);
+	}
 
 	public void testRemoveEntry() throws Exception {
-		String fullPathKey = FULL_PATH + "/testRemoveEntry";
+		String fullPathKey = fullPath + "/testRemoveEntry";
 		post(fullPathKey, "data", "application/text");
 		head(fullPathKey);
 		client.executeMethod(new DeleteMethod(fullPathKey));
@@ -219,18 +394,18 @@
 	}
 
 	public void testWipeCacheBucket() throws Exception {
-		String fullPathKey = FULL_PATH + "/testWipeCacheBucket";
+		String fullPathKey = fullPath + "/testWipeCacheBucket";
 		post(fullPathKey, "data", "application/text");
 		post(fullPathKey + "2", "data", "application/text");
 		head(fullPathKey);
 		head(fullPathKey + "2");
-		client.executeMethod(new DeleteMethod(FULL_PATH));
+		client.executeMethod(new DeleteMethod(fullPath));
 		head(fullPathKey, HttpServletResponse.SC_NOT_FOUND);
 		head(fullPathKey + "2", HttpServletResponse.SC_NOT_FOUND);
 	}
 
 	public void testAsyncAddRemove() throws Exception {
-		String fullPathKey = FULL_PATH + "/testAsyncAddRemove";
+		String fullPathKey = fullPath + "/testAsyncAddRemove";
 		post(fullPathKey, "data", "application/text", HttpServletResponse.SC_OK, 
 				// headers
 				"performAsync", "true" );
@@ -247,7 +422,7 @@
 	
 	// https://jira.jboss.org/browse/JBPAPP-5256
 	public void testPutUnknownClass() throws Exception {
-		String fullPathKey = FULL_PATH + "/testPutUnknownClass";
+		String fullPathKey = fullPath + "/testPutUnknownClass";
 
 		ByteArrayOutputStream bout = new ByteArrayOutputStream();
 		ObjectOutputStream oo = new ObjectOutputStream(bout);
@@ -264,7 +439,7 @@
 	}
 	
 	public void testETagChanges() throws Exception {
-		String fullPathKey = FULL_PATH + "/testETagChanges";
+		String fullPathKey = fullPath + "/testETagChanges";
 		put(fullPathKey, "data", "application/text");
 		String eTagFirst = get(fullPathKey).getResponseHeader("ETag").getValue();
 		// second get should get the same ETag
@@ -276,7 +451,7 @@
 	}
 	
 	public void testIfModifiedSince() throws Exception {
-		String fullPathKey = FULL_PATH + "/testIfModifiedSince";
+		String fullPathKey = fullPath + "/testIfModifiedSince";
 		put(fullPathKey, "data", "application/text");
 		String dateLast = get(fullPathKey).getResponseHeader("Last-Modified").getValue();
 		String dateMinus = addDay(dateLast, -1);
@@ -303,7 +478,7 @@
 
 	
 	public void testIfUnmodifiedSince() throws Exception {
-		String fullPathKey = FULL_PATH + "/testIfUnmodifiedSince";
+		String fullPathKey = fullPath + "/testIfUnmodifiedSince";
 		put(fullPathKey, "data", "application/text");
 		
 		String dateLast = get(fullPathKey).getResponseHeader("Last-Modified").getValue();
@@ -321,7 +496,7 @@
 	}
 
 	public void testIfNoneMatch() throws Exception {
-		String fullPathKey = FULL_PATH + "/testIfNoneMatch";
+		String fullPathKey = fullPath + "/testIfNoneMatch";
 		put(fullPathKey, "data", "application/text");
 		String eTag = get(fullPathKey).getResponseHeader("ETag").getValue();
 		
@@ -335,7 +510,7 @@
 	}
 	
 	public void testIfMatch() throws Exception {
-		String fullPathKey = FULL_PATH + "/testIfMatch";
+		String fullPathKey = fullPath + "/testIfMatch";
 		put(fullPathKey, "data", "application/text");
 		GetMethod get = get(fullPathKey);
 		
@@ -360,8 +535,8 @@
 	
 	// https://jira.jboss.org/browse/JBPAPP-5266
 	public void testNonExistentCache() throws Exception {
-		head(INFINISPAN_REST_PREFIX + "/nonexistentcache/nodata", HttpServletResponse.SC_NOT_FOUND);
-		get(INFINISPAN_REST_PREFIX + "/nonexistentcache/nodata", HttpServletResponse.SC_NOT_FOUND);
+		head(infinispanRestPrefix + "/nonexistentcache/nodata", HttpServletResponse.SC_NOT_FOUND);
+		get(infinispanRestPrefix + "/nonexistentcache/nodata", HttpServletResponse.SC_NOT_FOUND);
 	}
 	
 	//----------------------------------------- helper methods -----------------------------------------



More information about the jboss-cvs-commits mailing list