polygene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From paulmer...@apache.org
Subject [1/2] polygene-java git commit: riak-es: fix entityStates() failing since ee1d1abc
Date Wed, 11 Jan 2017 00:00:39 GMT
Repository: polygene-java
Updated Branches:
  refs/heads/develop 9b60364ef -> b05b04a1a


riak-es: fix entityStates() failing since ee1d1abc

refine main mixin
upgrade client library from 2.1.0 to 2.1.1
fix tests to gracefully tear down in case of failures


Project: http://git-wip-us.apache.org/repos/asf/polygene-java/repo
Commit: http://git-wip-us.apache.org/repos/asf/polygene-java/commit/f104f0c2
Tree: http://git-wip-us.apache.org/repos/asf/polygene-java/tree/f104f0c2
Diff: http://git-wip-us.apache.org/repos/asf/polygene-java/diff/f104f0c2

Branch: refs/heads/develop
Commit: f104f0c2689a4225c09c16574b43d614e48dbc38
Parents: 9b60364
Author: Paul Merlin <paulmerlin@apache.org>
Authored: Wed Jan 11 00:53:12 2017 +0100
Committer: Paul Merlin <paulmerlin@apache.org>
Committed: Wed Jan 11 00:53:12 2017 +0100

----------------------------------------------------------------------
 dependencies.gradle                             |  2 +-
 .../riak/RiakMapEntityStoreMixin.java           | 54 ++++++++++----------
 .../riak/RiakMapEntityStoreTest.java            | 25 ++++-----
 .../riak/RiakMapEntityStoreWithCacheTest.java   | 21 ++++----
 4 files changed, 52 insertions(+), 50 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/polygene-java/blob/f104f0c2/dependencies.gradle
----------------------------------------------------------------------
diff --git a/dependencies.gradle b/dependencies.gradle
index 48d7f27..6f6f0b9 100644
--- a/dependencies.gradle
+++ b/dependencies.gradle
@@ -66,7 +66,7 @@ def liquibaseVersion = '3.5.3'
 def mongodbVersion = '3.4.0'
 def restletVersion = '2.3.7'
 def rdfVersion = '2.7.16' // 2.8.x change query results!! 4.x exists
-def riakVersion = '2.1.0'
+def riakVersion = '2.1.1'
 def servletVersion = '3.1.0'
 def shiroVersion = '1.3.2'
 def slf4jVersion = '1.7.21'

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/f104f0c2/extensions/entitystore-riak/src/main/java/org/apache/polygene/entitystore/riak/RiakMapEntityStoreMixin.java
----------------------------------------------------------------------
diff --git a/extensions/entitystore-riak/src/main/java/org/apache/polygene/entitystore/riak/RiakMapEntityStoreMixin.java
b/extensions/entitystore-riak/src/main/java/org/apache/polygene/entitystore/riak/RiakMapEntityStoreMixin.java
index a94b559..df18dae 100644
--- a/extensions/entitystore-riak/src/main/java/org/apache/polygene/entitystore/riak/RiakMapEntityStoreMixin.java
+++ b/extensions/entitystore-riak/src/main/java/org/apache/polygene/entitystore/riak/RiakMapEntityStoreMixin.java
@@ -42,6 +42,7 @@ import java.security.Provider;
 import java.security.Security;
 import java.util.ArrayList;
 import java.util.List;
+import java.util.Objects;
 import java.util.concurrent.ExecutionException;
 import java.util.stream.Stream;
 import java.util.stream.StreamSupport;
@@ -70,7 +71,8 @@ public class RiakMapEntityStoreMixin implements ServiceActivation, MapEntityStor
     private Namespace namespace;
 
     @Override
-    public void activateService() throws Exception {
+    public void activateService() throws Exception
+    {
         // Load configuration
         configuration.refresh();
         RiakEntityStoreConfiguration config = configuration.get();
@@ -88,7 +90,7 @@ public class RiakMapEntityStoreMixin implements ServiceActivation, MapEntityStor
             nodes.add( nodeBuilder.withRemoteAddress( host ).build() );
         }
         RiakCluster.Builder clusterBuilder = RiakCluster.builder( nodes );
-        clusterBuilder = configureCluster(config, clusterBuilder);
+        clusterBuilder = configureCluster( config, clusterBuilder );
 
         // Start Riak Cluster
         RiakCluster cluster = clusterBuilder.build();
@@ -127,8 +129,9 @@ public class RiakMapEntityStoreMixin implements ServiceActivation, MapEntityStor
         return nodeBuilder;
     }
 
-    private RiakNode.Builder configureAuthentication( RiakEntityStoreConfiguration config,
RiakNode.Builder nodeBuilder )
-            throws IOException, GeneralSecurityException
+    private RiakNode.Builder configureAuthentication( RiakEntityStoreConfiguration config,
+                                                      RiakNode.Builder nodeBuilder )
+        throws IOException, GeneralSecurityException
     {
         String username = config.username().get();
         String password = config.password().get();
@@ -154,7 +157,8 @@ public class RiakMapEntityStoreMixin implements ServiceActivation, MapEntityStor
                     }
                     catch( Exception ex )
                     {
-                        throw new InvalidApplicationException( "Need to open a PKCS#12 but
was unable to register BouncyCastle, check your classpath", ex );
+                        throw new InvalidApplicationException(
+                            "Need to open a PKCS#12 but unable to register BouncyCastle,
check your classpath", ex );
                     }
                 }
             }
@@ -183,7 +187,8 @@ public class RiakMapEntityStoreMixin implements ServiceActivation, MapEntityStor
         }
     }
 
-    private RiakCluster.Builder configureCluster( RiakEntityStoreConfiguration config, RiakCluster.Builder
clusterBuilder )
+    private RiakCluster.Builder configureCluster( RiakEntityStoreConfiguration config,
+                                                  RiakCluster.Builder clusterBuilder )
     {
         Integer clusterExecutionAttempts = config.clusterExecutionAttempts().get();
         if( clusterExecutionAttempts != null )
@@ -195,7 +200,7 @@ public class RiakMapEntityStoreMixin implements ServiceActivation, MapEntityStor
 
     @Override
     public void passivateService()
-            throws Exception
+        throws Exception
     {
         riakClient.shutdown();
         riakClient = null;
@@ -215,8 +220,7 @@ public class RiakMapEntityStoreMixin implements ServiceActivation, MapEntityStor
     }
 
     @Override
-    public Reader get(EntityReference entityReference )
-            throws EntityStoreException
+    public Reader get( EntityReference entityReference )
     {
         try
         {
@@ -238,28 +242,25 @@ public class RiakMapEntityStoreMixin implements ServiceActivation, MapEntityStor
 
     @Override
     public void applyChanges( MapChanges changes )
-            throws IOException
     {
         try
         {
             changes.visitMap( new MapChanger()
             {
                 @Override
-                public Writer newEntity(final EntityReference ref, EntityDescriptor entityDescriptor
)
-                        throws IOException
+                public Writer newEntity( final EntityReference ref, EntityDescriptor entityDescriptor
)
                 {
                     return new StringWriter( 1000 )
                     {
                         @Override
-                        public void close()
-                                throws IOException
+                        public void close() throws IOException
                         {
                             try
                             {
                                 super.close();
                                 StoreValue store = new StoreValue.Builder( toString() )
-                                        .withLocation( new Location( namespace, ref.identity().toString()
) )
-                                        .build();
+                                    .withLocation( new Location( namespace, ref.identity().toString()
) )
+                                    .build();
                                 riakClient.execute( store );
                             }
                             catch( InterruptedException | ExecutionException ex )
@@ -272,13 +273,11 @@ public class RiakMapEntityStoreMixin implements ServiceActivation, MapEntityStor
 
                 @Override
                 public Writer updateEntity( final EntityReference ref, EntityDescriptor entityDescriptor
)
-                        throws IOException
                 {
                     return new StringWriter( 1000 )
                     {
                         @Override
-                        public void close()
-                                throws IOException
+                        public void close() throws IOException
                         {
                             try
                             {
@@ -290,7 +289,9 @@ public class RiakMapEntityStoreMixin implements ServiceActivation, MapEntityStor
                                 {
                                     throw new EntityNotFoundException( ref );
                                 }
-                                StoreValue store = new StoreValue.Builder( toString() ).withLocation(
location ).build();
+                                StoreValue store = new StoreValue.Builder( toString() )
+                                    .withLocation( location )
+                                    .build();
                                 riakClient.execute( store );
                             }
                             catch( InterruptedException | ExecutionException ex )
@@ -303,7 +304,6 @@ public class RiakMapEntityStoreMixin implements ServiceActivation, MapEntityStor
 
                 @Override
                 public void removeEntity( EntityReference ref, EntityDescriptor entityDescriptor
)
-                        throws EntityNotFoundException
                 {
                     try
                     {
@@ -345,14 +345,15 @@ public class RiakMapEntityStoreMixin implements ServiceActivation, MapEntityStor
                           {
                               FetchValue fetch = new FetchValue.Builder( location ).build();
                               FetchValue.Response response = riakClient.execute( fetch );
-                              String jsonState = response.getValue( String.class );
-                              return new StringReader( jsonState );
+                              return response.getValue( String.class );
                           }
                           catch( InterruptedException | ExecutionException ex )
                           {
                               throw new EntityStoreException( "Unable to get entity states.",
ex );
                           }
-                      } );
+                      } )
+                .filter( Objects::nonNull )
+                .map( StringReader::new );
         }
         catch( InterruptedException | ExecutionException ex )
         {
@@ -360,7 +361,6 @@ public class RiakMapEntityStoreMixin implements ServiceActivation, MapEntityStor
         }
     }
 
-
     private List<HostAndPort> parseHosts( List<String> hosts )
     {
         if( hosts.isEmpty() )
@@ -374,8 +374,8 @@ public class RiakMapEntityStoreMixin implements ServiceActivation, MapEntityStor
             int port = DEFAULT_PORT;
             if( splitted.length > 1 )
             {
-                host = splitted[0];
-                port = Integer.valueOf( splitted[1] );
+                host = splitted[ 0 ];
+                port = Integer.valueOf( splitted[ 1 ] );
             }
             addresses.add( HostAndPort.fromParts( host, port ) );
         }

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/f104f0c2/extensions/entitystore-riak/src/test/java/org/apache/polygene/entitystore/riak/RiakMapEntityStoreTest.java
----------------------------------------------------------------------
diff --git a/extensions/entitystore-riak/src/test/java/org/apache/polygene/entitystore/riak/RiakMapEntityStoreTest.java
b/extensions/entitystore-riak/src/test/java/org/apache/polygene/entitystore/riak/RiakMapEntityStoreTest.java
index 464451e..59f1714 100644
--- a/extensions/entitystore-riak/src/test/java/org/apache/polygene/entitystore/riak/RiakMapEntityStoreTest.java
+++ b/extensions/entitystore-riak/src/test/java/org/apache/polygene/entitystore/riak/RiakMapEntityStoreTest.java
@@ -34,7 +34,7 @@ import org.junit.BeforeClass;
 import static org.apache.polygene.test.util.Assume.assumeConnectivity;
 
 public class RiakMapEntityStoreTest
-        extends AbstractEntityStoreTest
+    extends AbstractEntityStoreTest
 {
     @BeforeClass
     public static void beforeRiakProtobufMapEntityStoreTests()
@@ -44,7 +44,7 @@ public class RiakMapEntityStoreTest
     @Override
     // START SNIPPET: assembly
     public void assemble( ModuleAssembly module )
-            throws AssemblyException
+        throws AssemblyException
     {
         // END SNIPPET: assembly
         super.assemble( module );
@@ -60,8 +60,7 @@ public class RiakMapEntityStoreTest
     private String bucketKey;
 
     @Override
-    public void setUp()
-            throws Exception
+    public void setUp() throws Exception
     {
         super.setUp();
         RiakMapEntityStoreService es = serviceFinder.findService( RiakMapEntityStoreService.class
).get();
@@ -70,17 +69,19 @@ public class RiakMapEntityStoreTest
     }
 
     @Override
-    public void tearDown()
-            throws Exception
+    public void tearDown() throws Exception
     {
         // Riak don't expose bucket deletion in its API so we empty the Polygene Entities
bucket.
-        Namespace namespace = new Namespace( bucketKey );
-        ListKeys listKeys = new ListKeys.Builder( namespace ).build();
-        ListKeys.Response listKeysResponse = riakClient.execute( listKeys );
-        for( Location location : listKeysResponse )
+        if( bucketKey != null )
         {
-            DeleteValue delete = new DeleteValue.Builder( location ).build();
-            riakClient.execute( delete );
+            Namespace namespace = new Namespace( bucketKey );
+            ListKeys listKeys = new ListKeys.Builder( namespace ).build();
+            ListKeys.Response listKeysResponse = riakClient.execute( listKeys );
+            for( Location location : listKeysResponse )
+            {
+                DeleteValue delete = new DeleteValue.Builder( location ).build();
+                riakClient.execute( delete );
+            }
         }
         super.tearDown();
     }

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/f104f0c2/extensions/entitystore-riak/src/test/java/org/apache/polygene/entitystore/riak/RiakMapEntityStoreWithCacheTest.java
----------------------------------------------------------------------
diff --git a/extensions/entitystore-riak/src/test/java/org/apache/polygene/entitystore/riak/RiakMapEntityStoreWithCacheTest.java
b/extensions/entitystore-riak/src/test/java/org/apache/polygene/entitystore/riak/RiakMapEntityStoreWithCacheTest.java
index 2c4771f..25feae1 100644
--- a/extensions/entitystore-riak/src/test/java/org/apache/polygene/entitystore/riak/RiakMapEntityStoreWithCacheTest.java
+++ b/extensions/entitystore-riak/src/test/java/org/apache/polygene/entitystore/riak/RiakMapEntityStoreWithCacheTest.java
@@ -59,8 +59,7 @@ public class RiakMapEntityStoreWithCacheTest
     private String bucketKey;
 
     @Override
-    public void setUp()
-        throws Exception
+    public void setUp() throws Exception
     {
         super.setUp();
         RiakMapEntityStoreService es = serviceFinder.findService( RiakMapEntityStoreService.class
).get();
@@ -69,17 +68,19 @@ public class RiakMapEntityStoreWithCacheTest
     }
 
     @Override
-    public void tearDown()
-        throws Exception
+    public void tearDown() throws Exception
     {
         // Riak don't expose bucket deletion in its API so we empty the Polygene Entities
bucket.
-        Namespace namespace = new Namespace( bucketKey );
-        ListKeys listKeys = new ListKeys.Builder( namespace ).build();
-        ListKeys.Response listKeysResponse = riakClient.execute( listKeys );
-        for( Location location : listKeysResponse )
+        if( bucketKey != null )
         {
-            DeleteValue delete = new DeleteValue.Builder( location ).build();
-            riakClient.execute( delete );
+            Namespace namespace = new Namespace( bucketKey );
+            ListKeys listKeys = new ListKeys.Builder( namespace ).build();
+            ListKeys.Response listKeysResponse = riakClient.execute( listKeys );
+            for( Location location : listKeysResponse )
+            {
+                DeleteValue delete = new DeleteValue.Builder( location ).build();
+                riakClient.execute( delete );
+            }
         }
         super.tearDown();
     }


Mime
View raw message