Author: gaohoward
Date: 2012-02-14 03:53:10 -0500 (Tue, 14 Feb 2012)
New Revision: 12110
Added:
trunk/tests/integration-tests/src/test/java/org/hornetq/tests/integration/persistence/JMSStorageManagerTest.java
Modified:
trunk/hornetq-jms/src/main/java/org/hornetq/jms/persistence/impl/journal/JMSJournalStorageManagerImpl.java
trunk/hornetq-jms/src/main/java/org/hornetq/jms/server/impl/JMSServerManagerImpl.java
trunk/tests/integration-tests/src/test/java/org/hornetq/tests/integration/jms/server/management/JMSQueueControlTest.java
Log:
HORNETQ-812
Modified:
trunk/hornetq-jms/src/main/java/org/hornetq/jms/persistence/impl/journal/JMSJournalStorageManagerImpl.java
===================================================================
---
trunk/hornetq-jms/src/main/java/org/hornetq/jms/persistence/impl/journal/JMSJournalStorageManagerImpl.java 2012-02-13
15:34:49 UTC (rev 12109)
+++
trunk/hornetq-jms/src/main/java/org/hornetq/jms/persistence/impl/journal/JMSJournalStorageManagerImpl.java 2012-02-14
08:53:10 UTC (rev 12110)
@@ -272,7 +272,6 @@
{
jmsJournal.appendDeleteRecord(destination.getId(), false);
}
- deleteJNDI(type, name);
}
/* (non-Javadoc)
Modified:
trunk/hornetq-jms/src/main/java/org/hornetq/jms/server/impl/JMSServerManagerImpl.java
===================================================================
---
trunk/hornetq-jms/src/main/java/org/hornetq/jms/server/impl/JMSServerManagerImpl.java 2012-02-13
15:34:49 UTC (rev 12109)
+++
trunk/hornetq-jms/src/main/java/org/hornetq/jms/server/impl/JMSServerManagerImpl.java 2012-02-14
08:53:10 UTC (rev 12110)
@@ -237,6 +237,8 @@
}
cachedCommands.clear();
+
+ recoverJndiBindings();
}
catch (Exception e)
@@ -244,7 +246,58 @@
JMSServerManagerImpl.log.error("Failed to start jms deployer", e);
}
}
+
+ private void recoverJndiBindings() throws Exception
+ {
+ //now its time to add journal recovered stuff
+ List<PersistedJNDI> jndiSpace = storage.recoverPersistedJNDI();
+
+ for (PersistedJNDI record : jndiSpace)
+ {
+ Map<String, List<String>> mapJNDI;
+ Map<String, ?> objects;
+ switch (record.getType())
+ {
+ case Queue:
+ mapJNDI = queueJNDI;
+ objects = queues;
+ break;
+ case Topic:
+ mapJNDI = topicJNDI;
+ objects = topics;
+ break;
+ default:
+ case ConnectionFactory:
+ mapJNDI = connectionFactoryJNDI;
+ objects = connectionFactories;
+ break;
+ }
+
+ Object objectToBind = objects.get(record.getName());
+
+ if (objectToBind == null)
+ {
+ continue;
+ }
+
+ List<String> jndiList = mapJNDI.get(record.getName());
+ if (jndiList == null)
+ {
+ jndiList = new ArrayList<String>();
+ mapJNDI.put(record.getName(), jndiList);
+ }
+
+ for (String jndi : record.getJndi())
+ {
+ jndiList.add(jndi);
+ bindToJndi(jndi, objectToBind);
+ }
+ }
+
+
+ }
+
// HornetQComponent implementation -----------------------------------
public synchronized void start() throws Exception
@@ -1535,50 +1588,6 @@
internalCreateTopic(destination.getName());
}
}
-
- List<PersistedJNDI> jndiSpace = storage.recoverPersistedJNDI();
- for (PersistedJNDI record : jndiSpace)
- {
- Map<String, List<String>> mapJNDI;
- Map<String, ?> objects;
-
- switch (record.getType())
- {
- case Queue:
- mapJNDI = queueJNDI;
- objects = queues;
- break;
- case Topic:
- mapJNDI = topicJNDI;
- objects = topics;
- break;
- default:
- case ConnectionFactory:
- mapJNDI = connectionFactoryJNDI;
- objects = connectionFactories;
- break;
- }
-
- Object objectToBind = objects.get(record.getName());
-
- if (objectToBind == null)
- {
- continue;
- }
-
- List<String> jndiList = mapJNDI.get(record.getName());
- if (jndiList == null)
- {
- jndiList = new ArrayList<String>();
- mapJNDI.put(record.getName(), jndiList);
- }
-
- for (String jndi : record.getJndi())
- {
- jndiList.add(jndi);
- bindToJndi(jndi, objectToBind);
- }
- }
}
/**
Modified:
trunk/tests/integration-tests/src/test/java/org/hornetq/tests/integration/jms/server/management/JMSQueueControlTest.java
===================================================================
---
trunk/tests/integration-tests/src/test/java/org/hornetq/tests/integration/jms/server/management/JMSQueueControlTest.java 2012-02-13
15:34:49 UTC (rev 12109)
+++
trunk/tests/integration-tests/src/test/java/org/hornetq/tests/integration/jms/server/management/JMSQueueControlTest.java 2012-02-14
08:53:10 UTC (rev 12110)
@@ -22,7 +22,6 @@
import javax.jms.Message;
import javax.jms.MessageConsumer;
import javax.jms.MessageProducer;
-import javax.jms.Queue;
import javax.jms.Session;
import javax.naming.Context;
@@ -1179,7 +1178,55 @@
e.printStackTrace();
}
}
+
+ public void testQueueAddJndi() throws Exception
+ {
+ String testQueueName = "testQueueAddJndi";
+ serverManager.createQueue(true, testQueueName, null, true, testQueueName);
+ HornetQQueue testQueue =
(HornetQQueue)HornetQJMSClient.createQueue(testQueueName);
+ JMSQueueControl queueControl = createManagementControl(testQueue);
+ String[] bindings = queueControl.getJNDIBindings();
+
+ String newJndi = "newTestQueueAddJndi";
+
+ for (String b : bindings)
+ {
+ assertFalse(b.equals(newJndi));
+ }
+ queueControl.addJNDI(newJndi);
+
+ bindings = queueControl.getJNDIBindings();
+ boolean newBindingAdded = false;
+ for (String b : bindings)
+ {
+ if (b.equals(newJndi))
+ {
+ newBindingAdded = true;
+ }
+ }
+ assertTrue(newBindingAdded);
+
+ serverManager.stop();
+
+ serverManager.start();
+
+ testQueue = (HornetQQueue)HornetQJMSClient.createQueue(testQueueName);
+
+ queueControl = createManagementControl(testQueue);
+
+ bindings = queueControl.getJNDIBindings();
+ newBindingAdded = false;
+ for (String b : bindings)
+ {
+ if (b.equals(newJndi))
+ {
+ newBindingAdded = true;
+ }
+ }
+ assertTrue(newBindingAdded);
+ }
+
// Package protected ---------------------------------------------
// Protected -----------------------------------------------------
Added:
trunk/tests/integration-tests/src/test/java/org/hornetq/tests/integration/persistence/JMSStorageManagerTest.java
===================================================================
---
trunk/tests/integration-tests/src/test/java/org/hornetq/tests/integration/persistence/JMSStorageManagerTest.java
(rev 0)
+++
trunk/tests/integration-tests/src/test/java/org/hornetq/tests/integration/persistence/JMSStorageManagerTest.java 2012-02-14
08:53:10 UTC (rev 12110)
@@ -0,0 +1,80 @@
+/*
+ * Copyright 2010 Red Hat, Inc.
+ * Red Hat licenses this file to you under the Apache License, version
+ * 2.0 (the "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ * implied. See the License for the specific language governing
+ * permissions and limitations under the License.
+ */
+package org.hornetq.tests.integration.persistence;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.hornetq.jms.persistence.config.PersistedConnectionFactory;
+import org.hornetq.jms.persistence.config.PersistedDestination;
+import org.hornetq.jms.persistence.config.PersistedJNDI;
+import org.hornetq.jms.persistence.config.PersistedType;
+import org.hornetq.jms.server.config.ConnectionFactoryConfiguration;
+import org.hornetq.jms.server.config.impl.ConnectionFactoryConfigurationImpl;
+
+/**
+ * A JMSStorageManagerTest
+ *
+ * @author <mailto:hgao@redhat.com">Howard Gao</a>
+ *
+ *
+ */
+public class JMSStorageManagerTest extends StorageManagerTestBase
+{
+ //https://issues.jboss.org/browse/HORNETQ-812
+ public void testJNDIPersistence() throws Exception
+ {
+ createJMSStorage();
+
+ jmsJournal.storeDestination(new PersistedDestination(PersistedType.Queue,
+ "jndiPersistQueue", null, true));
+
+ jmsJournal.addJNDI(PersistedType.Queue, "jndiPersistQueue",
"jndi-1");
+
+ List<PersistedDestination> destinations = jmsJournal.recoverDestinations();
+
+ List<PersistedJNDI> jndiList = jmsJournal.recoverPersistedJNDI();
+
+ assertEquals(1, destinations.size());
+
+ assertEquals(1, jndiList.size());
+
+ jmsJournal.deleteDestination(PersistedType.Queue, "jndiPersistQueue");
+
+ destinations = jmsJournal.recoverDestinations();
+
+ assertEquals(0, destinations.size());
+
+ jmsJournal.stop();
+
+ createJMSStorage();
+
+ destinations = jmsJournal.recoverDestinations();
+
+ assertEquals(0, destinations.size());
+
+ jndiList = jmsJournal.recoverPersistedJNDI();
+
+ assertEquals(1, jndiList.size());
+
+ PersistedJNDI jndi = jndiList.get(0);
+
+ List<String> jndis = jndi.getJndi();
+
+ assertEquals(1, jndis.size());
+
+ assertEquals("jndi-1", jndis.get(0));
+
+ }
+
+}