-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* [#25887] fix(JmsIO): issue with multiple connection open #25887 - Issue related to multiple connection being open for each bundle - Add integration test using jms-qpid for JmsIO Fixes #25887 Co-Authored-By: Amrane Ait Zeouay <[email protected]> * [#25887] fix(JmsIO): create new CommonJms instance instead of extending it #25887 Fixes #25887 Co-Authored-By: Amrane Ait Zeouay <[email protected]> * [#25887] fix(JmsIO): replacing flag with producer null verification #25887 Fixes #25887 Co-Authored-By: Amrane Ait Zeouay <[email protected]> * [#25887] fix(JmsIO): replace google timestamp with java instant #25887 Fixes #25887 Co-Authored-By: Amrane Ait Zeouay <[email protected]> --------- Co-authored-by: Amrane Ait Zeouay <[email protected]>
- Loading branch information
1 parent
ed93a34
commit e697569
Showing
11 changed files
with
620 additions
and
102 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
133 changes: 133 additions & 0 deletions
133
sdks/java/io/jms/src/test/java/org/apache/beam/sdk/io/jms/CommonJms.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,133 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF 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.apache.beam.sdk.io.jms; | ||
|
||
import java.io.Serializable; | ||
import java.nio.charset.StandardCharsets; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
import javax.jms.BytesMessage; | ||
import javax.jms.ConnectionFactory; | ||
import javax.jms.Message; | ||
import org.apache.activemq.ActiveMQConnectionFactory; | ||
import org.apache.activemq.broker.BrokerPlugin; | ||
import org.apache.activemq.broker.BrokerService; | ||
import org.apache.activemq.security.AuthenticationUser; | ||
import org.apache.activemq.security.SimpleAuthenticationPlugin; | ||
import org.apache.activemq.store.memory.MemoryPersistenceAdapter; | ||
import org.apache.activemq.transport.TransportFactory; | ||
import org.apache.activemq.transport.amqp.AmqpTransportFactory; | ||
|
||
/** | ||
* A common test fixture to create a broker and connection factories for {@link JmsIOIT} & {@link | ||
* JmsIOTest}. | ||
*/ | ||
public class CommonJms implements Serializable { | ||
private static final String BROKER_WITHOUT_PREFETCH_PARAM = "?jms.prefetchPolicy.all=0&"; | ||
|
||
static final String USERNAME = "test_user"; | ||
static final String PASSWORD = "test_password"; | ||
static final String QUEUE = "test_queue"; | ||
static final String TOPIC = "test_topic"; | ||
|
||
private final String brokerUrl; | ||
private final Integer brokerPort; | ||
private final String forceAsyncAcksParam; | ||
private transient BrokerService broker; | ||
|
||
protected ConnectionFactory connectionFactory; | ||
protected final Class<? extends ConnectionFactory> connectionFactoryClass; | ||
protected ConnectionFactory connectionFactoryWithSyncAcksAndWithoutPrefetch; | ||
|
||
public CommonJms( | ||
String brokerUrl, | ||
Integer brokerPort, | ||
String forceAsyncAcksParam, | ||
Class<? extends ConnectionFactory> connectionFactoryClass) { | ||
this.brokerUrl = brokerUrl; | ||
this.brokerPort = brokerPort; | ||
this.forceAsyncAcksParam = forceAsyncAcksParam; | ||
this.connectionFactoryClass = connectionFactoryClass; | ||
} | ||
|
||
void startBroker() throws Exception { | ||
broker = new BrokerService(); | ||
broker.setUseJmx(false); | ||
broker.setPersistenceAdapter(new MemoryPersistenceAdapter()); | ||
TransportFactory.registerTransportFactory("amqp", new AmqpTransportFactory()); | ||
if (connectionFactoryClass != ActiveMQConnectionFactory.class) { | ||
broker.addConnector(String.format("%s:%d?transport.transformer=jms", brokerUrl, brokerPort)); | ||
} else { | ||
broker.addConnector(brokerUrl); | ||
} | ||
broker.setBrokerName("localhost"); | ||
broker.setPopulateJMSXUserID(true); | ||
broker.setUseAuthenticatedPrincipalForJMSXUserID(true); | ||
broker.getManagementContext().setCreateConnector(false); | ||
|
||
// enable authentication | ||
List<AuthenticationUser> users = new ArrayList<>(); | ||
// username and password to use to connect to the broker. | ||
// This user has users privilege (able to browse, consume, produce, list destinations) | ||
users.add(new AuthenticationUser(USERNAME, PASSWORD, "users")); | ||
SimpleAuthenticationPlugin plugin = new SimpleAuthenticationPlugin(users); | ||
BrokerPlugin[] plugins = new BrokerPlugin[] {plugin}; | ||
broker.setPlugins(plugins); | ||
|
||
broker.start(); | ||
broker.waitUntilStarted(); | ||
|
||
// create JMS connection factory | ||
connectionFactory = connectionFactoryClass.getConstructor(String.class).newInstance(brokerUrl); | ||
connectionFactoryWithSyncAcksAndWithoutPrefetch = | ||
connectionFactoryClass | ||
.getConstructor(String.class) | ||
.newInstance(brokerUrl + BROKER_WITHOUT_PREFETCH_PARAM + forceAsyncAcksParam); | ||
} | ||
|
||
void stopBroker() throws Exception { | ||
broker.stop(); | ||
broker.waitUntilStopped(); | ||
broker = null; | ||
} | ||
|
||
Class<? extends ConnectionFactory> getConnectionFactoryClass() { | ||
return this.connectionFactoryClass; | ||
} | ||
|
||
ConnectionFactory getConnectionFactory() { | ||
return this.connectionFactory; | ||
} | ||
|
||
ConnectionFactory getConnectionFactoryWithSyncAcksAndWithoutPrefetch() { | ||
return this.connectionFactoryWithSyncAcksAndWithoutPrefetch; | ||
} | ||
|
||
/** A test class that maps a {@link javax.jms.BytesMessage} into a {@link String}. */ | ||
public static class BytesMessageToStringMessageMapper implements JmsIO.MessageMapper<String> { | ||
|
||
@Override | ||
public String mapMessage(Message message) throws Exception { | ||
BytesMessage bytesMessage = (BytesMessage) message; | ||
|
||
byte[] bytes = new byte[(int) bytesMessage.getBodyLength()]; | ||
|
||
return new String(bytes, StandardCharsets.UTF_8); | ||
} | ||
} | ||
} |
Oops, something went wrong.