Skip to content

Commit

Permalink
Some settings of WebSocket proxy are not effective (apache#3328)
Browse files Browse the repository at this point in the history
  • Loading branch information
massakam authored and merlimat committed Jan 8, 2019
1 parent ad72b7e commit 6ef4733
Show file tree
Hide file tree
Showing 3 changed files with 102 additions and 9 deletions.
6 changes: 3 additions & 3 deletions conf/websocket.conf
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,13 @@ bindAddress=0.0.0.0
clusterName=

# Number of IO threads in Pulsar Client used in WebSocket proxy
numIoThreads=8
webSocketNumIoThreads=8

# Number of threads to use in HTTP server. Default is Runtime.getRuntime().availableProcessors()
numHttpServerThreads=

# Number of connections per Broker in Pulsar Client used in WebSocket proxy
connectionsPerBroker=8
webSocketConnectionsPerBroker=8

# Time in milliseconds that idle WebSocket session times out
webSocketSessionIdleTimeoutMillis=300000
Expand Down Expand Up @@ -82,7 +82,7 @@ authorizationAllowWildcardsMatching=false
superUserRoles=

# Authentication settings of the proxy itself. Used to connect to brokers
brokerClientTlsEnabled=false;
brokerClientTlsEnabled=false
brokerClientAuthenticationPlugin=
brokerClientAuthenticationParameters=
brokerClientTrustCertsFilePath=
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/**
* 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.pulsar.websocket.proxy;

import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.spy;
import static org.testng.Assert.assertEquals;

import org.apache.bookkeeper.test.PortManager;
import org.apache.pulsar.client.api.ProducerConsumerBase;
import org.apache.pulsar.client.impl.PulsarClientImpl;
import org.apache.pulsar.websocket.WebSocketService;
import org.apache.pulsar.websocket.service.WebSocketProxyConfiguration;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;

public class ProxyConfigurationTest extends ProducerConsumerBase {
private WebSocketProxyConfiguration config;

@BeforeMethod
public void setup() throws Exception {
super.internalSetup();
super.producerBaseSetup();

config = new WebSocketProxyConfiguration();
config.setWebServicePort(PortManager.nextFreePort());
config.setClusterName("test");
config.setConfigurationStoreServers("dummy-zk-servers");
}

@AfterMethod
protected void cleanup() throws Exception {
super.internalCleanup();
}

@DataProvider(name = "setProxyConfig")
public Object[][] setProxyConfig() {
return new Object[][] { {2, 1}, {4, 2} };
}

@Test(dataProvider = "setProxyConfig", timeOut = 10000)
public void configTest(int numIoThreads, int connectionsPerBroker) throws Exception {
config.setWebSocketNumIoThreads(numIoThreads);
config.setWebSocketConnectionsPerBroker(connectionsPerBroker);
WebSocketService service = spy(new WebSocketService(config));
doReturn(mockZooKeeperClientFactory).when(service).getZooKeeperClientFactory();
service.start();

PulsarClientImpl client = (PulsarClientImpl) service.getPulsarClient();
assertEquals(client.getConfiguration().getNumIoThreads(), numIoThreads);
assertEquals(client.getConfiguration().getConnectionsPerBroker(), connectionsPerBroker);

service.close();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -90,13 +90,13 @@ public class WebSocketProxyConfiguration implements PulsarConfiguration {
private String brokerClientTrustCertsFilePath = "";

// Number of IO threads in Pulsar Client used in WebSocket proxy
private int numIoThreads = Runtime.getRuntime().availableProcessors();
private int webSocketNumIoThreads = Runtime.getRuntime().availableProcessors();

// Number of threads to use in HTTP server
private int numHttpServerThreads = Runtime.getRuntime().availableProcessors();

// Number of connections per Broker in Pulsar Client used in WebSocket proxy
private int connectionsPerBroker = Runtime.getRuntime().availableProcessors();
private int webSocketConnectionsPerBroker = Runtime.getRuntime().availableProcessors();
// Time in milliseconds that idle WebSocket session times out
private int webSocketSessionIdleTimeoutMillis = 300000;

Expand Down Expand Up @@ -292,12 +292,22 @@ public void setBrokerClientAuthenticationParameters(String brokerClientAuthentic
this.brokerClientAuthenticationParameters = brokerClientAuthenticationParameters;
}

@Deprecated
public int getNumIoThreads() {
return numIoThreads;
return getWebSocketNumIoThreads();
}

@Deprecated
public void setNumIoThreads(int numIoThreads) {
this.numIoThreads = numIoThreads;
setWebSocketNumIoThreads(numIoThreads);
}

public int getWebSocketNumIoThreads() {
return webSocketNumIoThreads;
}

public void setWebSocketNumIoThreads(int webSocketNumIoThreads) {
this.webSocketNumIoThreads = webSocketNumIoThreads;
}

public int getNumHttpServerThreads() {
Expand All @@ -308,12 +318,22 @@ public void setNumHttpServerThreads(int numHttpServerThreads) {
this.numHttpServerThreads = numHttpServerThreads;
}

@Deprecated
public int getConnectionsPerBroker() {
return connectionsPerBroker;
return getWebSocketConnectionsPerBroker();
}

@Deprecated
public void setConnectionsPerBroker(int connectionsPerBroker) {
this.connectionsPerBroker = connectionsPerBroker;
setWebSocketConnectionsPerBroker(connectionsPerBroker);
}

public int getWebSocketConnectionsPerBroker() {
return webSocketConnectionsPerBroker;
}

public void setWebSocketConnectionsPerBroker(int webSocketConnectionsPerBroker) {
this.webSocketConnectionsPerBroker = webSocketConnectionsPerBroker;
}

public int getWebSocketSessionIdleTimeoutMillis() {
Expand Down

0 comments on commit 6ef4733

Please sign in to comment.