Skip to content
4 changes: 4 additions & 0 deletions conf/client.conf
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,11 @@ tlsKeyStorePassword=
# When TLS authentication with KeyStore is used, available options can be SunJSSE, Conscrypt and so on.
webserviceTlsProvider=

#Proxy-server URL to which to connect
proxyServiceUrl=

#Proxy protocol to select type of routing at proxy
proxyProtocol=

# Pulsar Admin Custom Commands
#customCommandFactoriesDirectory=commandFactories
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ public static ClientBuilder createClientBuilderFromArguments(PerformanceBaseArgu
.enableBusyWait(arguments.enableBusyWait)
.listenerThreads(arguments.listenerThreads)
.tlsTrustCertsFilePath(arguments.tlsTrustCertsFilePath)
.maxLookupRequests(arguments.maxLookupRequest);
.maxLookupRequests(arguments.maxLookupRequest)
.proxyServiceUrl(arguments.proxyServiceURL, arguments.proxyProtocol);

if (isNotBlank(arguments.authPluginClassName)) {
clientBuilder.authentication(arguments.authPluginClassName, arguments.authParams);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,12 @@
package org.apache.pulsar.testclient;

import static org.apache.commons.lang3.StringUtils.isBlank;
import static org.apache.pulsar.testclient.PerfClientUtils.exit;
import com.beust.jcommander.Parameter;
import java.io.FileInputStream;
import java.util.Properties;
import lombok.SneakyThrows;
import org.apache.pulsar.client.api.ProxyProtocol;


public abstract class PerformanceBaseArguments {
Expand Down Expand Up @@ -85,6 +87,12 @@ public abstract class PerformanceBaseArguments {
+ "on each broker connection to prevent overloading a broker")
public int maxLookupRequest = 50000;

@Parameter(names = { "--proxy-url" }, description = "Proxy-server URL to which to connect.")
String proxyServiceURL = null;

@Parameter(names = { "--proxy-protocol" }, description = "Proxy protocol to select type of routing at proxy.")
ProxyProtocol proxyProtocol = null;

public abstract void fillArgumentsFromProperties(Properties prop);

@SneakyThrows
Expand Down Expand Up @@ -133,6 +141,25 @@ public void fillArgumentsFromProperties() {
.getProperty("tlsEnableHostnameVerification", ""));

}

if (proxyServiceURL == null) {
proxyServiceURL = prop.getProperty("proxyServiceURL");
}

if (proxyProtocol == null) {
try {
String proxyProtocolString = prop.getProperty("proxyProtocol");
if (proxyProtocolString != null) {
proxyProtocol = ProxyProtocol.valueOf(prop.getProperty("proxyProtocol"));
}
} catch (IllegalArgumentException e) {
System.out.println("Incorrect proxyProtocol name");
e.printStackTrace();
exit(-1);
}

}

fillArgumentsFromProperties(prop);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import java.util.Map;
import java.util.Properties;
import org.apache.pulsar.client.api.Authentication;
import org.apache.pulsar.client.api.ProxyProtocol;
import org.apache.pulsar.client.api.PulsarClientException;
import org.apache.pulsar.client.impl.ClientBuilderImpl;
import org.apache.pulsar.client.impl.conf.ClientConfigurationData;
Expand Down Expand Up @@ -71,6 +72,8 @@ public void fillArgumentsFromProperties(Properties prop) {
args.tlsTrustCertsFilePath = "path";
args.tlsAllowInsecureConnection = true;
args.maxLookupRequest = 100000;
args.proxyServiceURL = "pulsar+ssl://my-proxy-pulsar:4443";
args.proxyProtocol = ProxyProtocol.SNI;

final ClientBuilderImpl builder = (ClientBuilderImpl)PerfClientUtils.createClientBuilderFromArguments(args);
final ClientConfigurationData conf = builder.getClientConfigurationData();
Expand All @@ -88,6 +91,8 @@ public void fillArgumentsFromProperties(Properties prop) {
Assert.assertEquals(conf.getTlsTrustCertsFilePath(), "path");
Assert.assertTrue(conf.isTlsAllowInsecureConnection());
Assert.assertEquals(conf.getMaxLookupRequest(), 100000);
Assert.assertEquals(conf.getProxyServiceUrl(), "pulsar+ssl://my-proxy-pulsar:4443");
Assert.assertEquals(conf.getProxyProtocol(), ProxyProtocol.SNI);

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,19 @@
*/
package org.apache.pulsar.testclient;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Map;
import java.util.Properties;
import java.util.concurrent.atomic.AtomicBoolean;

import org.testng.Assert;
import org.testng.annotations.Test;

import static org.apache.pulsar.client.api.ProxyProtocol.SNI;
import static org.testng.Assert.fail;


public class PerformanceBaseArgumentsTest {

Expand All @@ -47,6 +55,111 @@ public void fillArgumentsFromProperties(Properties prop) {
Assert.assertEquals(args.tlsTrustCertsFilePath, "./path");
Assert.assertTrue(args.tlsAllowInsecureConnection);
Assert.assertTrue(args.tlsHostnameVerificationEnable);
Assert.assertEquals(args.proxyServiceURL, "https://my-proxy-pulsar:4443/");
Assert.assertEquals(args.proxyProtocol, SNI);
}

@Test
public void testReadFromConfigFileWithoutProxyUrl() {

AtomicBoolean called = new AtomicBoolean();

final PerformanceBaseArguments args = new PerformanceBaseArguments() {
@Override
public void fillArgumentsFromProperties(Properties prop) {
called.set(true);
}
};

File tempConfigFile = new File("./src/test/resources/performance_client2.conf");
if (tempConfigFile.exists()) {
tempConfigFile.delete();
}
try {
Properties props = new Properties();

Map<String, String> configs = Map.of("brokerServiceUrl","https://my-pulsar:8443/",
"authPlugin","org.apache.pulsar.testclient.PerfClientUtilsTest.MyAuth",
"authParams", "myparams",
"tlsTrustCertsFilePath", "./path",
"tlsAllowInsecureConnection","true",
"tlsEnableHostnameVerification", "true"
);
props.putAll(configs);
FileOutputStream out = new FileOutputStream(tempConfigFile);
props.store(out, "properties file");
out.close();
args.confFile = "./src/test/resources/performance_client2.conf";

args.fillArgumentsFromProperties();
Assert.assertTrue(called.get());
Assert.assertEquals(args.serviceURL, "https://my-pulsar:8443/");
Assert.assertEquals(args.authPluginClassName,
"org.apache.pulsar.testclient.PerfClientUtilsTest.MyAuth");
Assert.assertEquals(args.authParams, "myparams");
Assert.assertEquals(args.tlsTrustCertsFilePath, "./path");
Assert.assertTrue(args.tlsAllowInsecureConnection);
Assert.assertTrue(args.tlsHostnameVerificationEnable);

} catch (IOException e) {
e.printStackTrace();
fail("Error while updating/reading config file");
} finally {
tempConfigFile.delete();
}
}

@Test
public void testReadFromConfigFileProxyProtocolException() {

AtomicBoolean calledVar1 = new AtomicBoolean();
AtomicBoolean calledVar2 = new AtomicBoolean();

final PerformanceBaseArguments args = new PerformanceBaseArguments() {
@Override
public void fillArgumentsFromProperties(Properties prop) {
calledVar1.set(true);
}
};
File tempConfigFile = new File("./src/test/resources/performance_client3.conf");
if (tempConfigFile.exists()) {
tempConfigFile.delete();
}
try {
Properties props = new Properties();

Map<String, String> configs = Map.of("brokerServiceUrl","https://my-pulsar:8443/",
"authPlugin","org.apache.pulsar.testclient.PerfClientUtilsTest.MyAuth",
"authParams", "myparams",
"tlsTrustCertsFilePath", "./path",
"tlsAllowInsecureConnection","true",
"tlsEnableHostnameVerification", "true",
"proxyServiceURL", "https://my-proxy-pulsar:4443/",
"proxyProtocol", "TEST"
);
props.putAll(configs);
FileOutputStream out = new FileOutputStream(tempConfigFile);
props.store(out, "properties file");
out.close();
args.confFile = "./src/test/resources/performance_client3.conf";
PerfClientUtils.setExitProcedure(code -> {
calledVar2.set(true);
Assert.assertNotNull(code);
if (code != -1) {
fail("Incorrect exit code");
}
});

args.confFile = "./src/test/resources/performance_client3.conf";
args.fillArgumentsFromProperties();
Assert.assertTrue(calledVar1.get());
Assert.assertTrue(calledVar2.get());
} catch (IOException e) {
e.printStackTrace();
fail("Error while updating/reading config file");
} finally {
tempConfigFile.delete();
}
}

}
2 changes: 2 additions & 0 deletions pulsar-testclient/src/test/resources/perf_client1.conf
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,5 @@ authParams=myparams
tlsTrustCertsFilePath=./path
tlsAllowInsecureConnection=true
tlsEnableHostnameVerification=true
proxyServiceURL=https://my-proxy-pulsar:4443/

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this might fail any existing tests which are using this file.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The file is used by only one testcase "testReadFromConfigFile" which I have modified to work.

proxyProtocol=SNI