activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From clebertsuco...@apache.org
Subject [2/3] activemq-artemis git commit: ARTEMIS-162 Fix non serializable JGroups on Configuration clone used on Colocated support
Date Tue, 04 Aug 2015 15:46:07 GMT
ARTEMIS-162 Fix non serializable JGroups on Configuration clone used on Colocated support

https://issues.apache.org/jira/browse/ARTEMIS-162


Project: http://git-wip-us.apache.org/repos/asf/activemq-artemis/repo
Commit: http://git-wip-us.apache.org/repos/asf/activemq-artemis/commit/7cfc3379
Tree: http://git-wip-us.apache.org/repos/asf/activemq-artemis/tree/7cfc3379
Diff: http://git-wip-us.apache.org/repos/asf/activemq-artemis/diff/7cfc3379

Branch: refs/heads/master
Commit: 7cfc33790d710436fe1de9aea844f0350cc60e16
Parents: 39b9fd1
Author: Clebert Suconic <clebertsuconic@apache.org>
Authored: Mon Aug 3 16:49:40 2015 -0400
Committer: Clebert Suconic <clebertsuconic@apache.org>
Committed: Mon Aug 3 23:39:35 2015 -0400

----------------------------------------------------------------------
 .../core/config/impl/ConfigurationImpl.java     | 34 ++++++++++++++++----
 .../core/config/impl/ConfigurationImplTest.java | 16 ++-------
 ...tionFactoryWithJGroupsSerializationTest.java | 13 ++++++--
 3 files changed, 41 insertions(+), 22 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/7cfc3379/artemis-server/src/main/java/org/apache/activemq/artemis/core/config/impl/ConfigurationImpl.java
----------------------------------------------------------------------
diff --git a/artemis-server/src/main/java/org/apache/activemq/artemis/core/config/impl/ConfigurationImpl.java
b/artemis-server/src/main/java/org/apache/activemq/artemis/core/config/impl/ConfigurationImpl.java
index 0f0616b..c6dab0e 100644
--- a/artemis-server/src/main/java/org/apache/activemq/artemis/core/config/impl/ConfigurationImpl.java
+++ b/artemis-server/src/main/java/org/apache/activemq/artemis/core/config/impl/ConfigurationImpl.java
@@ -23,6 +23,8 @@ import java.io.ObjectInputStream;
 import java.io.ObjectOutputStream;
 import java.io.Serializable;
 import java.net.URI;
+import java.security.AccessController;
+import java.security.PrivilegedExceptionAction;
 import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.HashSet;
@@ -50,6 +52,7 @@ import org.apache.activemq.artemis.core.server.JournalType;
 import org.apache.activemq.artemis.core.server.group.impl.GroupingHandlerConfiguration;
 import org.apache.activemq.artemis.core.settings.impl.AddressSettings;
 import org.apache.activemq.artemis.core.settings.impl.ResourceLimitSettings;
+import org.apache.activemq.artemis.utils.ObjectInputStreamWithClassLoader;
 
 public class ConfigurationImpl implements Configuration, Serializable
 {
@@ -114,9 +117,9 @@ public class ConfigurationImpl implements Configuration, Serializable
 
    private List<CoreQueueConfiguration> queueConfigurations = new ArrayList<CoreQueueConfiguration>();
 
-   protected List<BroadcastGroupConfiguration> broadcastGroupConfigurations = new ArrayList<BroadcastGroupConfiguration>();
+   protected transient List<BroadcastGroupConfiguration> broadcastGroupConfigurations
= new ArrayList<BroadcastGroupConfiguration>();
 
-   protected Map<String, DiscoveryGroupConfiguration> discoveryGroupConfigurations
= new LinkedHashMap<String, DiscoveryGroupConfiguration>();
+   protected transient Map<String, DiscoveryGroupConfiguration> discoveryGroupConfigurations
= new LinkedHashMap<String, DiscoveryGroupConfiguration>();
 
    // Paging related attributes ------------------------------------------------------------
 
@@ -1586,11 +1589,28 @@ public class ConfigurationImpl implements Configuration, Serializable
    @Override
    public Configuration copy() throws Exception
    {
-      ByteArrayOutputStream bos = new ByteArrayOutputStream();
-      ObjectOutputStream os = new ObjectOutputStream(bos);
-      os.writeObject(this);
-      ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(bos.toByteArray()));
-      return (Configuration) ois.readObject();
+
+      return AccessController.doPrivileged(new PrivilegedExceptionAction<Configuration>()
+      {
+         @Override
+         public Configuration run() throws Exception
+         {
+            ByteArrayOutputStream bos = new ByteArrayOutputStream();
+            ObjectOutputStream os = new ObjectOutputStream(bos);
+            os.writeObject(ConfigurationImpl.this);
+            ObjectInputStream ois = new ObjectInputStreamWithClassLoader(new ByteArrayInputStream(bos.toByteArray()));
+            Configuration config = (Configuration) ois.readObject();
+
+            // this is transient because of possible jgroups integration, we need to copy
it manually
+            config.setBroadcastGroupConfigurations(ConfigurationImpl.this.getBroadcastGroupConfigurations());
+
+            // this is transient because of possible jgroups integration, we need to copy
it manually
+            config.setDiscoveryGroupConfigurations(ConfigurationImpl.this.getDiscoveryGroupConfigurations());
+
+            return config;
+         }
+      });
+
    }
 
    @Override

http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/7cfc3379/artemis-server/src/test/java/org/apache/activemq/artemis/core/config/impl/ConfigurationImplTest.java
----------------------------------------------------------------------
diff --git a/artemis-server/src/test/java/org/apache/activemq/artemis/core/config/impl/ConfigurationImplTest.java
b/artemis-server/src/test/java/org/apache/activemq/artemis/core/config/impl/ConfigurationImplTest.java
index dd9f584..b6d036f 100644
--- a/artemis-server/src/test/java/org/apache/activemq/artemis/core/config/impl/ConfigurationImplTest.java
+++ b/artemis-server/src/test/java/org/apache/activemq/artemis/core/config/impl/ConfigurationImplTest.java
@@ -22,17 +22,12 @@ import org.apache.activemq.artemis.core.config.Configuration;
 import org.apache.activemq.artemis.core.config.ha.LiveOnlyPolicyConfiguration;
 import org.apache.activemq.artemis.core.journal.impl.JournalConstants;
 import org.apache.activemq.artemis.core.server.JournalType;
-import org.apache.activemq.artemis.tests.util.RandomUtil;
 import org.apache.activemq.artemis.tests.util.ActiveMQTestBase;
+import org.apache.activemq.artemis.tests.util.RandomUtil;
 import org.junit.Assert;
 import org.junit.Before;
 import org.junit.Test;
 
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.ObjectInputStream;
-import java.io.ObjectOutputStream;
-
 public class ConfigurationImplTest extends ActiveMQTestBase
 {
    protected Configuration conf;
@@ -497,14 +492,9 @@ public class ConfigurationImplTest extends ActiveMQTestBase
       conf.setClusterPassword(s);
       Assert.assertEquals(s, conf.getClusterPassword());
 
-      ByteArrayOutputStream baos = new ByteArrayOutputStream();
-      ObjectOutputStream oos = new ObjectOutputStream(baos);
-      oos.writeObject(conf);
-      oos.flush();
+      // This will use serialization to perform a deep copy of the object
+      Configuration conf2 = conf.copy();
 
-      ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
-      ObjectInputStream ois = new ObjectInputStream(bais);
-      Configuration conf2 = (Configuration)ois.readObject();
 
       Assert.assertTrue(conf.equals(conf2));
    }

http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/7cfc3379/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/jms/connection/ConnectionFactoryWithJGroupsSerializationTest.java
----------------------------------------------------------------------
diff --git a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/jms/connection/ConnectionFactoryWithJGroupsSerializationTest.java
b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/jms/connection/ConnectionFactoryWithJGroupsSerializationTest.java
index 4b58ee1..bf50760 100644
--- a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/jms/connection/ConnectionFactoryWithJGroupsSerializationTest.java
+++ b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/jms/connection/ConnectionFactoryWithJGroupsSerializationTest.java
@@ -16,6 +16,7 @@
  */
 package org.apache.activemq.artemis.tests.integration.jms.connection;
 
+import javax.jms.Queue;
 import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
 import java.io.IOException;
@@ -23,19 +24,19 @@ import java.io.ObjectInputStream;
 import java.io.ObjectOutputStream;
 import java.io.Serializable;
 
-import javax.jms.Queue;
-
 import org.apache.activemq.artemis.api.core.BroadcastEndpoint;
 import org.apache.activemq.artemis.api.core.BroadcastEndpointFactory;
 import org.apache.activemq.artemis.api.core.ChannelBroadcastEndpointFactory;
 import org.apache.activemq.artemis.api.core.DiscoveryGroupConfiguration;
 import org.apache.activemq.artemis.api.core.JGroupsFileBroadcastEndpointFactory;
 import org.apache.activemq.artemis.api.jms.JMSFactoryType;
+import org.apache.activemq.artemis.core.config.Configuration;
 import org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory;
 import org.apache.activemq.artemis.tests.util.JMSTestBase;
 import org.jgroups.JChannel;
 import org.jgroups.conf.PlainConfigurator;
 import org.junit.After;
+import org.junit.Assert;
 import org.junit.Before;
 import org.junit.Test;
 
@@ -168,6 +169,14 @@ public class ConnectionFactoryWithJGroupsSerializationTest extends JMSTestBase
       assertTrue(broadcastEndpoint instanceof JGroupsFileBroadcastEndpointFactory);
    }
 
+   @Test
+   public void testCopyConfiguration() throws Exception
+   {
+      Assert.assertEquals(2, jmsServer.getActiveMQServer().getConfiguration().getDiscoveryGroupConfigurations().size());
+      Configuration copiedconfig = jmsServer.getActiveMQServer().getConfiguration().copy();
+      Assert.assertEquals(2, copiedconfig.getDiscoveryGroupConfigurations().size());
+   }
+
    @Override
    @After
    public void tearDown() throws Exception


Mime
View raw message