Author: ieb Date: Tue Feb 26 03:03:08 2013 New Revision: 1450003 URL: http://svn.apache.org/r1450003 Log: SLING-2750 moved the null check on instance inside the synchronised method to conform to rules about double null checks and synchronised blocks.
Modified: sling/trunk/bundles/commons/testing/src/main/java/org/apache/sling/commons/testing/integration/HttpTestBase.java sling/trunk/bundles/commons/testing/src/main/java/org/apache/sling/commons/testing/jcr/RepositoryProvider.java Modified: sling/trunk/bundles/commons/testing/src/main/java/org/apache/sling/commons/testing/integration/HttpTestBase.java URL: http://svn.apache.org/viewvc/sling/trunk/bundles/commons/testing/src/main/java/org/apache/sling/commons/testing/integration/HttpTestBase.java?rev=1450003&r1=1450002&r2=1450003&view=diff ============================================================================== --- sling/trunk/bundles/commons/testing/src/main/java/org/apache/sling/commons/testing/integration/HttpTestBase.java (original) +++ sling/trunk/bundles/commons/testing/src/main/java/org/apache/sling/commons/testing/integration/HttpTestBase.java Tue Feb 26 03:03:08 2013 @@ -84,6 +84,8 @@ public class HttpTestBase extends TestCa /** Means "don't care about Content-Type" in getContent(...) methods */ public static final String CONTENT_TYPE_DONTCARE = "*"; + private static final Object startupCheckLock = new Object(); + /** URLs stored here are deleted in tearDown */ protected final List<String> urlsToDelete = new LinkedList<String>(); @@ -196,17 +198,21 @@ public class HttpTestBase extends TestCa */ protected void waitForSlingStartup() throws Exception { // Use a static flag to make sure this runs only once in our test suite - if (slingStartupOk != null) { - if(slingStartupOk) { + // we must synchronize on this if we don't 2 threads could enter the check concurrently + // which would leave to random results. + synchronized(startupCheckLock) { + if (slingStartupOk != null) { + if(slingStartupOk) { + return; + } + fail("Sling services not available. Already checked in earlier tests."); + } + if ( System.getProperty(PROPERTY_SKIP_STARTUP_CHECK) != null ) { + slingStartupOk = true; return; } - fail("Sling services not available. Already checked in earlier tests."); - } - if ( System.getProperty(PROPERTY_SKIP_STARTUP_CHECK) != null ) { - slingStartupOk = true; - return; + slingStartupOk = false; } - slingStartupOk = false; System.err.println("Checking if the required Sling services are started (timeout " + READY_TIMEOUT_SECONDS + " seconds)..."); System.err.println("(base URLs=" + HTTP_BASE_URL + " and " + WEBDAV_BASE_URL + "; servlet context="+ SERVLET_CONTEXT +")"); Modified: sling/trunk/bundles/commons/testing/src/main/java/org/apache/sling/commons/testing/jcr/RepositoryProvider.java URL: http://svn.apache.org/viewvc/sling/trunk/bundles/commons/testing/src/main/java/org/apache/sling/commons/testing/jcr/RepositoryProvider.java?rev=1450003&r1=1450002&r2=1450003&view=diff ============================================================================== --- sling/trunk/bundles/commons/testing/src/main/java/org/apache/sling/commons/testing/jcr/RepositoryProvider.java (original) +++ sling/trunk/bundles/commons/testing/src/main/java/org/apache/sling/commons/testing/jcr/RepositoryProvider.java Tue Feb 26 03:03:08 2013 @@ -44,13 +44,9 @@ public class RepositoryProvider { private RepositoryProvider() { } - public static RepositoryProvider instance() { + public synchronized static RepositoryProvider instance() { if(INSTANCE == null) { - synchronized (RepositoryProvider.class) { - if(INSTANCE == null) { - INSTANCE = new RepositoryProvider(); - } - } + INSTANCE = new RepositoryProvider(); } return INSTANCE; } @@ -58,18 +54,12 @@ public class RepositoryProvider { /** Return a SlingRepository. First call initializes it, and a JVM * shutdown hook is registered to stop it. **/ - public SlingRepository getRepository() throws RepositoryException { - if(repository != null) { - return repository; - } - - synchronized (RepositoryTestBase.class) { - if(repository == null) { - RepositoryUtil.startRepository(); - repository = RepositoryUtil.getRepository(); - Runtime.getRuntime().addShutdownHook(new ShutdownThread()); - } - return repository; + public synchronized SlingRepository getRepository() throws RepositoryException { + if(repository == null) { + RepositoryUtil.startRepository(); + repository = RepositoryUtil.getRepository(); + Runtime.getRuntime().addShutdownHook(new ShutdownThread()); } + return repository; } } \ No newline at end of file