This closes #106 fixes

This commit is contained in:
Clebert Suconic 2015-08-04 11:45:38 -04:00
commit bff0886b0c
6 changed files with 49 additions and 30 deletions

View File

@ -23,6 +23,8 @@ import java.io.ObjectInputStream;
import java.io.ObjectOutputStream; import java.io.ObjectOutputStream;
import java.io.Serializable; import java.io.Serializable;
import java.net.URI; import java.net.URI;
import java.security.AccessController;
import java.security.PrivilegedExceptionAction;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet; 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.server.group.impl.GroupingHandlerConfiguration;
import org.apache.activemq.artemis.core.settings.impl.AddressSettings; import org.apache.activemq.artemis.core.settings.impl.AddressSettings;
import org.apache.activemq.artemis.core.settings.impl.ResourceLimitSettings; import org.apache.activemq.artemis.core.settings.impl.ResourceLimitSettings;
import org.apache.activemq.artemis.utils.ObjectInputStreamWithClassLoader;
public class ConfigurationImpl implements Configuration, Serializable public class ConfigurationImpl implements Configuration, Serializable
{ {
@ -114,9 +117,9 @@ public class ConfigurationImpl implements Configuration, Serializable
private List<CoreQueueConfiguration> queueConfigurations = new ArrayList<CoreQueueConfiguration>(); 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 ------------------------------------------------------------ // Paging related attributes ------------------------------------------------------------
@ -1586,11 +1589,28 @@ public class ConfigurationImpl implements Configuration, Serializable
@Override @Override
public Configuration copy() throws Exception public Configuration copy() throws Exception
{ {
ByteArrayOutputStream bos = new ByteArrayOutputStream();
ObjectOutputStream os = new ObjectOutputStream(bos); return AccessController.doPrivileged(new PrivilegedExceptionAction<Configuration>()
os.writeObject(this); {
ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(bos.toByteArray())); @Override
return (Configuration) ois.readObject(); 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 @Override

View File

@ -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.config.ha.LiveOnlyPolicyConfiguration;
import org.apache.activemq.artemis.core.journal.impl.JournalConstants; import org.apache.activemq.artemis.core.journal.impl.JournalConstants;
import org.apache.activemq.artemis.core.server.JournalType; 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.ActiveMQTestBase;
import org.apache.activemq.artemis.tests.util.RandomUtil;
import org.junit.Assert; import org.junit.Assert;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; 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 public class ConfigurationImplTest extends ActiveMQTestBase
{ {
protected Configuration conf; protected Configuration conf;
@ -497,14 +492,9 @@ public class ConfigurationImplTest extends ActiveMQTestBase
conf.setClusterPassword(s); conf.setClusterPassword(s);
Assert.assertEquals(s, conf.getClusterPassword()); Assert.assertEquals(s, conf.getClusterPassword());
ByteArrayOutputStream baos = new ByteArrayOutputStream(); // This will use serialization to perform a deep copy of the object
ObjectOutputStream oos = new ObjectOutputStream(baos); Configuration conf2 = conf.copy();
oos.writeObject(conf);
oos.flush();
ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
ObjectInputStream ois = new ObjectInputStream(bais);
Configuration conf2 = (Configuration)ois.readObject();
Assert.assertTrue(conf.equals(conf2)); Assert.assertTrue(conf.equals(conf2));
} }

View File

@ -125,7 +125,7 @@ public class ClosingConnectionTest extends ActiveMQTestBase
@BMRule @BMRule
( (
name = "rule to kill connection", name = "rule to kill connection",
targetClass = "org.apache.activemq.artemis.core.journal.impl.NIOSequentialFile", targetClass = "org.apache.activemq.artemis.core.io.nio.NIOSequentialFile",
targetMethod = "open(int, boolean)", targetMethod = "open(int, boolean)",
targetLocation = "AT INVOKE java.nio.channels.FileChannel.size()", targetLocation = "AT INVOKE java.nio.channels.FileChannel.size()",
action = "org.apache.activemq.artemis.tests.extras.byteman.ClosingConnectionTest.killConnection();" action = "org.apache.activemq.artemis.tests.extras.byteman.ClosingConnectionTest.killConnection();"

View File

@ -16,6 +16,10 @@
*/ */
package org.apache.activemq.artemis.tests.extras.byteman; package org.apache.activemq.artemis.tests.extras.byteman;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.atomic.AtomicInteger;
import org.apache.activemq.artemis.api.core.SimpleString; import org.apache.activemq.artemis.api.core.SimpleString;
import org.apache.activemq.artemis.api.core.client.ClientConsumer; import org.apache.activemq.artemis.api.core.client.ClientConsumer;
import org.apache.activemq.artemis.api.core.client.ClientMessage; import org.apache.activemq.artemis.api.core.client.ClientMessage;
@ -38,10 +42,6 @@ import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.atomic.AtomicInteger;
@RunWith(BMUnitRunner.class) @RunWith(BMUnitRunner.class)
public class PagingLeakTest extends ActiveMQTestBase public class PagingLeakTest extends ActiveMQTestBase
{ {
@ -122,7 +122,7 @@ public class PagingLeakTest extends ActiveMQTestBase
// A backup that will be waiting to be activated // A backup that will be waiting to be activated
Configuration config = createDefaultNettyConfig(); Configuration config = createDefaultNettyConfig();
config.setJournalBufferTimeout_AIO(0).setJournalBufferTimeout_NIO(0); config.setJournalBufferTimeout_AIO(10).setJournalBufferTimeout_NIO(10);
final ActiveMQServer server = addServer(ActiveMQServers.newActiveMQServer(config, true)); final ActiveMQServer server = addServer(ActiveMQServers.newActiveMQServer(config, true));

View File

@ -1345,7 +1345,7 @@ public class BridgeTest extends ActiveMQTestBase
Map<String, Object> server1Params = new HashMap<String, Object>(); Map<String, Object> server1Params = new HashMap<String, Object>();
addTargetParameters(server1Params); addTargetParameters(server1Params);
server1 = createClusteredServerWithParams(isNetty(), 1, true, PAGE_SIZE, PAGE_MAX, server1Params); server1 = createClusteredServerWithParams(isNetty(), 1, true, PAGE_SIZE, PAGE_MAX, server1Params);
server1.getConfiguration().setJournalBufferTimeout_AIO(0).setJournalBufferTimeout_NIO(0); server1.getConfiguration().setJournalBufferTimeout_AIO(10).setJournalBufferTimeout_NIO(10);
final String testAddress = "testAddress"; final String testAddress = "testAddress";
final String queueName0 = "queue0"; final String queueName0 = "queue0";
@ -1360,7 +1360,7 @@ public class BridgeTest extends ActiveMQTestBase
server0.getConfiguration().setConnectorConfigurations(connectors); server0.getConfiguration().setConnectorConfigurations(connectors);
server0.getConfiguration().setIDCacheSize(20000).setJournalBufferTimeout_NIO(0).setJournalBufferTimeout_AIO(0); server0.getConfiguration().setIDCacheSize(20000).setJournalBufferTimeout_NIO(10).setJournalBufferTimeout_AIO(10);
ArrayList<String> staticConnectors = new ArrayList<String>(); ArrayList<String> staticConnectors = new ArrayList<String>();
staticConnectors.add(server1tc.getName()); staticConnectors.add(server1tc.getName());

View File

@ -16,6 +16,7 @@
*/ */
package org.apache.activemq.artemis.tests.integration.jms.connection; package org.apache.activemq.artemis.tests.integration.jms.connection;
import javax.jms.Queue;
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import java.io.IOException; import java.io.IOException;
@ -23,19 +24,19 @@ import java.io.ObjectInputStream;
import java.io.ObjectOutputStream; import java.io.ObjectOutputStream;
import java.io.Serializable; import java.io.Serializable;
import javax.jms.Queue;
import org.apache.activemq.artemis.api.core.BroadcastEndpoint; import org.apache.activemq.artemis.api.core.BroadcastEndpoint;
import org.apache.activemq.artemis.api.core.BroadcastEndpointFactory; import org.apache.activemq.artemis.api.core.BroadcastEndpointFactory;
import org.apache.activemq.artemis.api.core.ChannelBroadcastEndpointFactory; import org.apache.activemq.artemis.api.core.ChannelBroadcastEndpointFactory;
import org.apache.activemq.artemis.api.core.DiscoveryGroupConfiguration; import org.apache.activemq.artemis.api.core.DiscoveryGroupConfiguration;
import org.apache.activemq.artemis.api.core.JGroupsFileBroadcastEndpointFactory; import org.apache.activemq.artemis.api.core.JGroupsFileBroadcastEndpointFactory;
import org.apache.activemq.artemis.api.jms.JMSFactoryType; 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.jms.client.ActiveMQConnectionFactory;
import org.apache.activemq.artemis.tests.util.JMSTestBase; import org.apache.activemq.artemis.tests.util.JMSTestBase;
import org.jgroups.JChannel; import org.jgroups.JChannel;
import org.jgroups.conf.PlainConfigurator; import org.jgroups.conf.PlainConfigurator;
import org.junit.After; import org.junit.After;
import org.junit.Assert;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
@ -168,6 +169,14 @@ public class ConnectionFactoryWithJGroupsSerializationTest extends JMSTestBase
assertTrue(broadcastEndpoint instanceof JGroupsFileBroadcastEndpointFactory); 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 @Override
@After @After
public void tearDown() throws Exception public void tearDown() throws Exception