Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[cli-protonj2] Disable shared tests that don't work #503

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/*
* Copyright (c) 2022 Red Hat, Inc.
*
* 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 com.redhat.mqe;

import org.apache.qpid.protonj2.client.Client;
import org.apache.qpid.protonj2.client.Connection;
import org.apache.qpid.protonj2.client.ConnectionOptions;
import picocli.CommandLine;

import java.net.URI;
import java.util.concurrent.Callable;

@CommandLine.Command(
name = "connector",
mixinStandardHelpOptions = true,
version = "1.0.0",
description = "Opens AMQP connections"
)
class CliProtonJ2Connector implements Callable<Integer> {
@CommandLine.Option(names = {"-b", "--broker"}, description = "")
private String broker = "";

@CommandLine.Option(names = {"-a", "--address"}, description = "")
private String address = "";

@CommandLine.Option(names = {"--count"}, description = "")
private int count = 1;

@Override
public Integer call() throws Exception {
String prefix = "";
if (!broker.startsWith("amqp://") && !broker.startsWith("amqps://")) {
prefix = "amqp://";
}
final URI url = new URI(prefix + broker);
final String serverHost = url.getHost();
int serverPort = url.getPort();
serverPort = (serverPort == -1) ? 5672 : serverPort;

final Client client = Client.create();

final ConnectionOptions options = new ConnectionOptions();
options.user(System.getProperty("USER"));
options.password(System.getProperty("PASSWORD"));

try (Connection connection = client.connect(serverHost, serverPort, options)) {
}

client.close();

return 0;
}
}
44 changes: 6 additions & 38 deletions cli-protonj2/src/main/java/com/redhat/mqe/CliProtonJ2Receiver.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import org.apache.qpid.protonj2.client.Delivery;
import org.apache.qpid.protonj2.client.DistributionMode;
import org.apache.qpid.protonj2.client.DurabilityMode;
import org.apache.qpid.protonj2.client.ExpiryPolicy;
import org.apache.qpid.protonj2.client.Message;
import org.apache.qpid.protonj2.client.Receiver;
import org.apache.qpid.protonj2.client.ReceiverOptions;
Expand Down Expand Up @@ -70,18 +69,12 @@ public class CliProtonJ2Receiver extends CliProtonJ2SenderReceiver implements Ca
@CommandLine.Option(names = {"--out"}, description = "MD5, SHA-1, SHA-256, ...")
private Out out = Out.python;

@CommandLine.Option(names = {"--msg-content-hashed"})
private String msgContentHashedString = "false";
@CommandLine.Option(names = {"--msg-content-hashed"}, arity = "0..1")
private boolean msgContentHashed = false;

@CommandLine.Option(names = {"-b", "--broker"}, description = "MD5, SHA-1, SHA-256, ...")
private String broker = "MD5";

@CommandLine.Option(names = {"--conn-username"}, description = "MD5, SHA-1, SHA-256, ...")
private String connUsername = "MD5";

@CommandLine.Option(names = {"--conn-password"}, description = "MD5, SHA-1, SHA-256, ...")
private String connPassword = "MD5";

@CommandLine.Option(names = {"--conn-clientid"})
private String connClientId;

Expand Down Expand Up @@ -109,10 +102,6 @@ public class CliProtonJ2Receiver extends CliProtonJ2SenderReceiver implements Ca
@CommandLine.Option(names = {"--timeout"}, description = "MD5, SHA-1, SHA-256, ...")
private int timeout;

@CommandLine.Option(names = {"--conn-auth-mechanisms"}, description = "MD5, SHA-1, SHA-256, ...")
// todo, want to accept comma-separated lists; there is https://picocli.info/#_split_regex
private List<AuthMechanism> connAuthMechanisms = new ArrayList<>();

@CommandLine.Option(names = {"--process-reply-to"})
private boolean processReplyTo = false;

Expand All @@ -137,15 +126,9 @@ public class CliProtonJ2Receiver extends CliProtonJ2SenderReceiver implements Ca
@CommandLine.Option(names = {"--msg-content-to-file"})
private String msgContentToFile;

@CommandLine.Option(names = {"--conn-reconnect"})
private String reconnectString = "false";

@CommandLine.Option(names = {"--conn-prefetch"})
private Integer connPrefetch;

@CommandLine.Option(names = {"--conn-heartbeat"})
private Long connHeartbeat;

public CliProtonJ2Receiver() {
this.messageFormatter = new ProtonJ2MessageFormatter();
}
Expand Down Expand Up @@ -196,25 +179,10 @@ public Integer call() throws Exception {
client = Client.create();
}

final ConnectionOptions options = new ConnectionOptions();
if (stringToBool(reconnectString)) {
options.reconnectEnabled(true);
}
if (connHeartbeat != null) {
options.idleTimeout(2 * connHeartbeat, TimeUnit.SECONDS);
}
options.user(connUsername);
options.password(connPassword);
for (AuthMechanism mech : connAuthMechanisms) {
options.saslOptions().addAllowedMechanism(mech.name());
}

// TODO: what do I actually need/want here?
// TODO, same problem, lib has Symbols in ClientConstants class
// cli proton cpp does not do this, btw
// options.desiredCapabilities(
// "sole-connection-for-container", "DELAYED_DELIVERY", "SHARED-SUBS", "ANONYMOUS-RELAY"
// );
final ConnectionOptions options = getConnectionOptions();



/*
TODO API usability, hard to ask for queue when dealing with broker that likes to autocreate topics
Expand Down Expand Up @@ -382,7 +350,7 @@ public Integer call() throws Exception {
private void outputReceivedMessage(int i, Delivery delivery) throws ClientException, IOException {
Message<Object> message = delivery.message();
int messageFormat = delivery.messageFormat();
Map<String, Object> messageDict = messageFormatter.formatMessage(address, message, stringToBool(msgContentHashedString));
Map<String, Object> messageDict = messageFormatter.formatMessage(address, message, msgContentHashed);
if (msgContentToFile != null) {
// todo?
Path file = Paths.get(msgContentToFile + "_" + i);
Expand Down
39 changes: 4 additions & 35 deletions cli-protonj2/src/main/java/com/redhat/mqe/CliProtonJ2Sender.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
import java.util.List;
import java.util.Map;
import java.util.concurrent.Callable;
import java.util.concurrent.TimeUnit;

import static com.redhat.mqe.lib.ClientOptionManager.QUEUE_PREFIX;
import static com.redhat.mqe.lib.ClientOptionManager.TOPIC_PREFIX;
Expand All @@ -57,18 +56,12 @@ public class CliProtonJ2Sender extends CliProtonJ2SenderReceiver implements Call
@CommandLine.Option(names = {"--out"}, description = "MD5, SHA-1, SHA-256, ...")
private Out out = Out.python;

@CommandLine.Option(names = {"--msg-content-hashed"})
private String msgContentHashedString = "false";
@CommandLine.Option(names = {"--msg-content-hashed"}, arity = "0..1")
private boolean msgContentHashed = false;

@CommandLine.Option(names = {"-b", "--broker"}, description = "")
private String broker = "MD5";

@CommandLine.Option(names = {"--conn-username"}, description = "")
private String connUsername = "MD5";

@CommandLine.Option(names = {"--conn-password"}, description = "")
private String connPassword = "MD5";

@CommandLine.Option(names = {"-a", "--address"}, description = "")
private String address = "MD5";

Expand All @@ -81,10 +74,6 @@ public class CliProtonJ2Sender extends CliProtonJ2SenderReceiver implements Call
@CommandLine.Option(names = {"--duration"})
private Float duration = 0.0f;

@CommandLine.Option(names = {"--conn-auth-mechanisms"}, description = "MD5, SHA-1, SHA-256, ...")
// todo, want to accept comma-separated lists; there is https://picocli.info/#_split_regex
private List<AuthMechanism> connAuthMechanisms = new ArrayList<>();

@CommandLine.Option(names = {"--msg-property"}) // picocli Map options works for this, sounds like
private List<String> msgProperties = new ArrayList<>();

Expand Down Expand Up @@ -169,12 +158,6 @@ public class CliProtonJ2Sender extends CliProtonJ2SenderReceiver implements Call
@CommandLine.Option(names = {"--duration-mode"})
private DurationModeSender durationMode = DurationModeSender.afterSend;

@CommandLine.Option(names = {"--conn-reconnect"})
private String reconnectString = "false";

@CommandLine.Option(names = {"--conn-heartbeat"})
private Long connHeartbeat;

public CliProtonJ2Sender() {
this.messageFormatter = new ProtonJ2MessageFormatter();
}
Expand Down Expand Up @@ -210,21 +193,7 @@ public Integer call() throws Exception { // your business logic goes here...

final Client client = Client.create();

final ConnectionOptions options = new ConnectionOptions();
// TODO typo in javadoc: This option enables or disables reconnection to a remote remote peer after IO errors. To control
// TODO API: unclear if reconnect is on or off by default (public static final boolean DEFAULT_RECONNECT_ENABLED = false;)
if (stringToBool(reconnectString)) {
options.reconnectEnabled(true);
}
if (connHeartbeat != null) {
// TODO finish that 2x investigation for heartbeats and document it somewhere (jira?)
options.idleTimeout(2 * connHeartbeat, TimeUnit.SECONDS);
}
options.user(connUsername);
options.password(connPassword);
for (AuthMechanism mech : connAuthMechanisms) {
options.saslOptions().addAllowedMechanism(mech.name());
}
final ConnectionOptions options = getConnectionOptions();

/*
TODO API usablility, hard to ask for queue when dealing with broker that likes to autocreate topics
Expand Down Expand Up @@ -343,7 +312,7 @@ private void performMessageSending(boolean transacted, @NotNull Sender sender, @
}

private void printMessage(Message<Object> message) throws ClientException {
Map<String, Object> messageDict = messageFormatter.formatMessage(address, message, stringToBool(msgContentHashedString));
Map<String, Object> messageDict = messageFormatter.formatMessage(address, message, msgContentHashed);
switch (out) {
case python:
switch (logMsgs) {
Expand Down
Loading