ARTEMIS-4243 Fix export of bindings without routing types
This commit is contained in:
parent
673481369f
commit
4e77a34c29
|
@ -67,6 +67,7 @@ import org.apache.activemq.artemis.utils.collections.LinkedListIterator;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import java.lang.invoke.MethodHandles;
|
import java.lang.invoke.MethodHandles;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
@Command(name = "exp", description = "Export all message-data using an XML that could be interpreted by any system.")
|
@Command(name = "exp", description = "Export all message-data using an XML that could be interpreted by any system.")
|
||||||
public final class XmlDataExporter extends DBOption {
|
public final class XmlDataExporter extends DBOption {
|
||||||
|
@ -340,11 +341,9 @@ public final class XmlDataExporter extends DBOption {
|
||||||
for (Map.Entry<Long, PersistentAddressBindingEncoding> addressBindingEncodingEntry : addressBindings.entrySet()) {
|
for (Map.Entry<Long, PersistentAddressBindingEncoding> addressBindingEncodingEntry : addressBindings.entrySet()) {
|
||||||
PersistentAddressBindingEncoding bindingEncoding = addressBindings.get(addressBindingEncodingEntry.getKey());
|
PersistentAddressBindingEncoding bindingEncoding = addressBindings.get(addressBindingEncodingEntry.getKey());
|
||||||
xmlWriter.writeEmptyElement(XmlDataConstants.ADDRESS_BINDINGS_CHILD);
|
xmlWriter.writeEmptyElement(XmlDataConstants.ADDRESS_BINDINGS_CHILD);
|
||||||
StringBuilder routingTypes = new StringBuilder();
|
String routingTypes = bindingEncoding.getRoutingTypes().stream().
|
||||||
for (RoutingType routingType : bindingEncoding.getRoutingTypes()) {
|
map(Enum::toString).collect(Collectors.joining(","));
|
||||||
routingTypes.append(routingType.toString()).append(", ");
|
xmlWriter.writeAttribute(XmlDataConstants.ADDRESS_BINDING_ROUTING_TYPE, routingTypes);
|
||||||
}
|
|
||||||
xmlWriter.writeAttribute(XmlDataConstants.ADDRESS_BINDING_ROUTING_TYPE, routingTypes.toString().substring(0, routingTypes.length() - 2));
|
|
||||||
xmlWriter.writeAttribute(XmlDataConstants.ADDRESS_BINDING_NAME, bindingEncoding.getName().toString());
|
xmlWriter.writeAttribute(XmlDataConstants.ADDRESS_BINDING_NAME, bindingEncoding.getName().toString());
|
||||||
xmlWriter.writeAttribute(XmlDataConstants.ADDRESS_BINDING_ID, Long.toString(bindingEncoding.getId()));
|
xmlWriter.writeAttribute(XmlDataConstants.ADDRESS_BINDING_ID, Long.toString(bindingEncoding.getId()));
|
||||||
bindingsPrinted++;
|
bindingsPrinted++;
|
||||||
|
|
|
@ -1164,6 +1164,42 @@ public class XmlImportExportTest extends ActiveMQTestBase {
|
||||||
assertTrue(server.getAddressInfo(myAddress).getRoutingTypes().contains(RoutingType.MULTICAST));
|
assertTrue(server.getAddressInfo(myAddress).getRoutingTypes().contains(RoutingType.MULTICAST));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testEmptyRoutingTypes() throws Exception {
|
||||||
|
SimpleString myAddress = SimpleString.toSimpleString("myAddress");
|
||||||
|
ClientSession session = basicSetUp();
|
||||||
|
|
||||||
|
EnumSet<RoutingType> routingTypes = EnumSet.noneOf(RoutingType.class);
|
||||||
|
|
||||||
|
session.createAddress(myAddress, routingTypes, false);
|
||||||
|
|
||||||
|
locator.close();
|
||||||
|
server.stop();
|
||||||
|
|
||||||
|
ByteArrayOutputStream xmlOutputStream = new ByteArrayOutputStream();
|
||||||
|
XmlDataExporter xmlDataExporter = new XmlDataExporter();
|
||||||
|
xmlDataExporter.process(xmlOutputStream, server.getConfiguration().getBindingsDirectory(), server.getConfiguration().getJournalDirectory(), server.getConfiguration().getPagingDirectory(), server.getConfiguration().getLargeMessagesDirectory());
|
||||||
|
if (logger.isDebugEnabled()) {
|
||||||
|
logger.debug(new String(xmlOutputStream.toByteArray()));
|
||||||
|
}
|
||||||
|
|
||||||
|
clearDataRecreateServerDirs();
|
||||||
|
server.start();
|
||||||
|
checkForLongs();
|
||||||
|
locator = createInVMNonHALocator();
|
||||||
|
factory = locator.createSessionFactory();
|
||||||
|
session = factory.createSession(false, false, true);
|
||||||
|
ClientSession managementSession = factory.createSession(false, true, true);
|
||||||
|
|
||||||
|
ByteArrayInputStream xmlInputStream = new ByteArrayInputStream(xmlOutputStream.toByteArray());
|
||||||
|
XmlDataImporter xmlDataImporter = new XmlDataImporter();
|
||||||
|
xmlDataImporter.validate(xmlInputStream);
|
||||||
|
xmlInputStream.reset();
|
||||||
|
xmlDataImporter.process(xmlInputStream, session, managementSession);
|
||||||
|
|
||||||
|
assertEquals(0, server.getAddressInfo(myAddress).getRoutingTypes().size());
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testImportWrongRoutingType() throws Exception {
|
public void testImportWrongRoutingType() throws Exception {
|
||||||
SimpleString myAddress = SimpleString.toSimpleString("myAddress");
|
SimpleString myAddress = SimpleString.toSimpleString("myAddress");
|
||||||
|
|
Loading…
Reference in New Issue