You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by bd...@apache.org on 2015/07/28 16:28:42 UTC
svn commit: r1693098 -
/sling/trunk/contrib/extensions/bgservlets/testing/src/test/java/org/apache/sling/bgservlets/it/BackgroundRequestIT.java
Author: bdelacretaz
Date: Tue Jul 28 14:28:42 2015
New Revision: 1693098
URL: http://svn.apache.org/r1693098
Log:
SLING-4899 - verify Sling instance ID in jobs storage path
Modified:
sling/trunk/contrib/extensions/bgservlets/testing/src/test/java/org/apache/sling/bgservlets/it/BackgroundRequestIT.java
Modified: sling/trunk/contrib/extensions/bgservlets/testing/src/test/java/org/apache/sling/bgservlets/it/BackgroundRequestIT.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/bgservlets/testing/src/test/java/org/apache/sling/bgservlets/it/BackgroundRequestIT.java?rev=1693098&r1=1693097&r2=1693098&view=diff
==============================================================================
--- sling/trunk/contrib/extensions/bgservlets/testing/src/test/java/org/apache/sling/bgservlets/it/BackgroundRequestIT.java (original)
+++ sling/trunk/contrib/extensions/bgservlets/testing/src/test/java/org/apache/sling/bgservlets/it/BackgroundRequestIT.java Tue Jul 28 14:28:42 2015
@@ -24,9 +24,13 @@ import static org.junit.Assert.fail;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.StringReader;
+import java.util.Iterator;
+import java.util.regex.Pattern;
import junit.framework.AssertionFailedError;
+import org.apache.sling.commons.json.JSONException;
+import org.apache.sling.commons.json.JSONObject;
import org.apache.sling.commons.testing.integration.HttpTest;
import org.junit.Before;
import org.junit.Test;
@@ -59,7 +63,7 @@ public class BackgroundRequestIT {
}
@Test
- public void testTmpRequestCreatesJob() throws IOException,InterruptedException {
+ public void testTmpRequestCreatesJob() throws IOException,InterruptedException, JSONException {
final int initialJobs = countStoredJobs();
T.getContent(HttpTest.HTTP_BASE_URL + "/tmp.json?sling:bg=true", "application/json");
@@ -75,6 +79,22 @@ public class BackgroundRequestIT {
Thread.sleep(50L);
}
+ // Verify that jobs are stored under a path that includes the Sling instance ID
+ final String path = "/var/bg/jobs.tidy.1.json";
+ final JSONObject json = new JSONObject(T.getContent(HttpTest.HTTP_BASE_URL + path, "application/json"));
+ int matches = 0;
+ final Pattern instanceIdPattern = Pattern.compile("([0-9a-fA-F\\\\-]){20,}");
+ final Iterator<String> it = json.keys();
+ while(it.hasNext()) {
+ final String key = it.next();
+ if(instanceIdPattern.matcher(key).matches()) {
+ matches++;
+ }
+ }
+ if(matches == 0) {
+ fail("No instance ID node found under " + path);
+ }
+
// Wait a bit - no more jobs should be created
Thread.sleep(2000L);
assertEquals("Expecting no extra jobs", initialJobs + 1, countStoredJobs());