You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@usergrid.apache.org by to...@apache.org on 2015/01/21 00:15:14 UTC

[2/2] incubator-usergrid git commit: Changed barrier back to file. File is now named uniquely per build to avoid collisions.

Changed barrier back to file.  File is now named uniquely per build to avoid collisions.


Project: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/commit/d35cba68
Tree: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/tree/d35cba68
Diff: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/diff/d35cba68

Branch: refs/heads/USERGRID-273
Commit: d35cba68b51b9e34f33d19f6b70139aaee2acce4
Parents: d2e5da6
Author: Todd Nine <tn...@apigee.com>
Authored: Tue Jan 20 16:15:11 2015 -0700
Committer: Todd Nine <tn...@apigee.com>
Committed: Tue Jan 20 16:15:11 2015 -0700

----------------------------------------------------------------------
 stack/core/pom.xml                              |  2 +-
 stack/pom.xml                                   |  2 +-
 .../usergrid/lock/MultiProcessBarrier.java      | 54 +++++++-------------
 .../org/apache/usergrid/setup/SystemSetup.java  |  4 +-
 .../usergrid/lock/MultiProcessBarrierTest.java  | 10 ++--
 5 files changed, 25 insertions(+), 47 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/d35cba68/stack/core/pom.xml
----------------------------------------------------------------------
diff --git a/stack/core/pom.xml b/stack/core/pom.xml
index 71d2522..5d9da98 100644
--- a/stack/core/pom.xml
+++ b/stack/core/pom.xml
@@ -87,7 +87,7 @@
           <forkCount>${usergrid.it.forkCount}</forkCount>
           <threadCount>${usergrid.it.threads}</threadCount>
           <reuseForks>true</reuseForks>
-          <argLine>-Xmx${ug.heapmax} -Xms${ug.heapmin} -Dfile.encoding=UTF-8 -Dsun.jnu.encoding=UTF-8 -javaagent:${settings.localRepository}/com/github/stephenc/jamm/0.2.5/jamm-0.2.5.jar ${ug.argline}</argLine>
+          <argLine>-Dtest.barrier.timestamp=${maven.build.timestamp} -Xmx${ug.heapmax} -Xms${ug.heapmin} -Dfile.encoding=UTF-8 -Dsun.jnu.encoding=UTF-8 -javaagent:${settings.localRepository}/com/github/stephenc/jamm/0.2.5/jamm-0.2.5.jar ${ug.argline}</argLine>
           <includes>
             <include>**/*IT.java</include>
             <include>**/*Test.java</include>

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/d35cba68/stack/pom.xml
----------------------------------------------------------------------
diff --git a/stack/pom.xml b/stack/pom.xml
index f17e0f5..5ddaa43 100644
--- a/stack/pom.xml
+++ b/stack/pom.xml
@@ -87,7 +87,7 @@
     <!-- you can override these via MAVEN_OPTS -->
     <ug.heapmax>4096m</ug.heapmax>
     <ug.heapmin>2048m</ug.heapmin>
-	<ug.argline>-Djava.awt.headless=true</ug.argline>
+	  <ug.argline>-Djava.awt.headless=true</ug.argline>
 
     <usergrid-custom-spring-properties>classpath:/usergrid-deployment.properties</usergrid-custom-spring-properties>
     <usergrid-custom-spring-test-properties>classpath:/usergrid-custom-test.properties</usergrid-custom-spring-test-properties>

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/d35cba68/stack/test-utils/src/main/java/org/apache/usergrid/lock/MultiProcessBarrier.java
----------------------------------------------------------------------
diff --git a/stack/test-utils/src/main/java/org/apache/usergrid/lock/MultiProcessBarrier.java b/stack/test-utils/src/main/java/org/apache/usergrid/lock/MultiProcessBarrier.java
index 7b4e290..cd5a1de 100644
--- a/stack/test-utils/src/main/java/org/apache/usergrid/lock/MultiProcessBarrier.java
+++ b/stack/test-utils/src/main/java/org/apache/usergrid/lock/MultiProcessBarrier.java
@@ -20,29 +20,26 @@
 package org.apache.usergrid.lock;
 
 
+import java.io.File;
 import java.io.IOException;
-import java.net.InetSocketAddress;
-import java.net.ServerSocket;
-import java.net.Socket;
 import java.util.concurrent.TimeoutException;
 
 
 /**
- * A barrier between processes and threads. Everyone will await until proceed has been invoked by a single thread.
- * Other threads will proceed after wait time.
+ * A barrier between processes and threads. Everyone will await until proceed has been invoked by a single
+ * thread.  Other threads will proceed after wait time.
  */
 public class MultiProcessBarrier {
 
     /**
      * The sleep time to wait before checking.
      */
-    private static final int SLEEP_TIME = 100;
-    public final int barrierPort;
-    public ServerSocket serverSocket;
+    private static final long SLEEP_TIME = 100;
+    public final File barrierFile;
 
 
-    public MultiProcessBarrier( final int barrierPort ) {
-        this.barrierPort = barrierPort;
+    public MultiProcessBarrier( final String barrierFileName ) {
+        this.barrierFile = new File( barrierFileName );
     }
 
 
@@ -50,46 +47,31 @@ public class MultiProcessBarrier {
      * Notify the other processes they can proceed.
      */
     public void proceed() throws IOException {
-        serverSocket = new ServerSocket( barrierPort );
+        barrierFile.mkdirs();
+        barrierFile.createNewFile();
     }
 
 
     /**
      * Await the specified file.  If it exists, it will proceed
+     * @param timeout
+     * @throws InterruptedException
+     * @throws TimeoutException
      */
-    public void await( final long timeout ) throws InterruptedException, TimeoutException {
+    public void await(final long timeout) throws InterruptedException, TimeoutException {
 
         final long stopTime = System.currentTimeMillis() + timeout;
 
-        while ( System.currentTimeMillis() < stopTime ) {
-
-
-            try {
-                Socket client = new Socket();
-                client.connect( new InetSocketAddress( "127.0.0.1", barrierPort ), SLEEP_TIME );
-                //if we get here we're good, the client can connect and close
-                client.close();
-
-                finalize();
+        while(System.currentTimeMillis() < stopTime){
 
+            //barrier is done break
+            if(barrierFile.exists()){
                 return;
             }
-            catch ( IOException e ) {
-                //not open swallow and retry
-            }
-            catch ( Throwable throwable ) {
-                throw new RuntimeException( "Something unexpected happened", throwable );
-            }
+
+            Thread.sleep( SLEEP_TIME );
         }
 
         throw new TimeoutException( "Timeout out after " + timeout + " milliseconds waiting for the file" );
     }
-
-
-    @Override
-    protected void finalize() throws Throwable {
-        if ( serverSocket != null && !serverSocket.isClosed() ) {
-            serverSocket.close();
-        }
-    }
 }

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/d35cba68/stack/test-utils/src/main/java/org/apache/usergrid/setup/SystemSetup.java
----------------------------------------------------------------------
diff --git a/stack/test-utils/src/main/java/org/apache/usergrid/setup/SystemSetup.java b/stack/test-utils/src/main/java/org/apache/usergrid/setup/SystemSetup.java
index 9460365..9e0e86e 100644
--- a/stack/test-utils/src/main/java/org/apache/usergrid/setup/SystemSetup.java
+++ b/stack/test-utils/src/main/java/org/apache/usergrid/setup/SystemSetup.java
@@ -37,15 +37,15 @@ import org.apache.usergrid.persistence.index.impl.ElasticSearchResource;
  */
 public class SystemSetup {
 
+    private static final String TEMP_FILE_PATH = "target/surefirelocks/start_barrier-" + System.getProperty( "test.barrier.timestamp", "default" );
 
     public static final int LOCK_PORT = Integer.parseInt( System.getProperty( "test.lock.port", "10101") );
-    public static final int START_BARRIER_PORT =  Integer.parseInt( System.getProperty( "test.barrier.port", "10102") );
 
 
     public static final long ONE_MINUTE = 60000;
 
     final MultiProcessLocalLock lock = new MultiProcessLocalLock( LOCK_PORT );
-    final MultiProcessBarrier barrier = new MultiProcessBarrier( START_BARRIER_PORT );
+    final MultiProcessBarrier barrier = new MultiProcessBarrier( TEMP_FILE_PATH );
 
 
     /**

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/d35cba68/stack/test-utils/src/test/java/org/apache/usergrid/lock/MultiProcessBarrierTest.java
----------------------------------------------------------------------
diff --git a/stack/test-utils/src/test/java/org/apache/usergrid/lock/MultiProcessBarrierTest.java b/stack/test-utils/src/test/java/org/apache/usergrid/lock/MultiProcessBarrierTest.java
index 5863041..3fe0e57 100644
--- a/stack/test-utils/src/test/java/org/apache/usergrid/lock/MultiProcessBarrierTest.java
+++ b/stack/test-utils/src/test/java/org/apache/usergrid/lock/MultiProcessBarrierTest.java
@@ -43,15 +43,11 @@ import static org.junit.Assert.fail;
 public class MultiProcessBarrierTest {
 
 
-    public static final int START_BARRIER_PORT =  Integer.parseInt( System.getProperty( "test.barrier.port", "10102") );
-
-
-
     @Test
     public void singleBarrierTest() throws IOException, InterruptedException, TimeoutException {
         final String file = newFileName();
 
-        final MultiProcessBarrier barrier = new MultiProcessBarrier( START_BARRIER_PORT );
+        final MultiProcessBarrier barrier = new MultiProcessBarrier( file );
 
 
         try {
@@ -84,7 +80,7 @@ public class MultiProcessBarrierTest {
 
         //now create the barrier and execute it
 
-        MultiProcessBarrier barrier = new MultiProcessBarrier( START_BARRIER_PORT );
+        MultiProcessBarrier barrier = new MultiProcessBarrier( file );
         barrier.proceed();
 
         assertTrue( "other barriers proceeded", latch.await( 1000, TimeUnit.MILLISECONDS ) );
@@ -124,7 +120,7 @@ public class MultiProcessBarrierTest {
         @Override
         public void run() {
 
-            MultiProcessBarrier barrier = new MultiProcessBarrier( START_BARRIER_PORT );
+            MultiProcessBarrier barrier = new MultiProcessBarrier( fileName );
 
 
             try {