-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
Pass brokerServiceUrl to websocket service configuration #166
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
113 changes: 113 additions & 0 deletions
113
...oker/src/test/java/com/yahoo/pulsar/websocket/proxy/ProxyPublishConsumeWithoutZKTest.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,113 @@ | ||
/** | ||
* Copyright 2016 Yahoo Inc. | ||
* | ||
* Licensed 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.yahoo.pulsar.websocket.proxy; | ||
|
||
import static org.mockito.Mockito.doReturn; | ||
import static org.mockito.Mockito.spy; | ||
|
||
import java.net.URI; | ||
import java.util.concurrent.Future; | ||
import java.util.concurrent.TimeUnit; | ||
|
||
import org.eclipse.jetty.websocket.api.Session; | ||
import org.eclipse.jetty.websocket.client.ClientUpgradeRequest; | ||
import org.eclipse.jetty.websocket.client.WebSocketClient; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.testng.Assert; | ||
import org.testng.annotations.AfterClass; | ||
import org.testng.annotations.BeforeClass; | ||
import org.testng.annotations.Test; | ||
|
||
import com.yahoo.pulsar.client.api.ProducerConsumerBase; | ||
import com.yahoo.pulsar.websocket.WebSocketService; | ||
import com.yahoo.pulsar.websocket.service.ProxyServer; | ||
import com.yahoo.pulsar.websocket.service.WebSocketProxyConfiguration; | ||
import com.yahoo.pulsar.websocket.service.WebSocketServiceStarter; | ||
|
||
public class ProxyPublishConsumeWithoutZKTest extends ProducerConsumerBase { | ||
protected String methodName; | ||
private static final String CONSUME_URI = "ws://localhost:6080/ws/consumer/persistent/my-property/use/my-ns/my-topic/my-sub"; | ||
private static final String PRODUCE_URI = "ws://localhost:6080/ws/producer/persistent/my-property/use/my-ns/my-topic/"; | ||
private static final int TEST_PORT = 6080; | ||
private ProxyServer proxyServer; | ||
private WebSocketService service; | ||
|
||
@BeforeClass | ||
public void setup() throws Exception { | ||
super.internalSetup(); | ||
super.producerBaseSetup(); | ||
|
||
WebSocketProxyConfiguration config = new WebSocketProxyConfiguration(); | ||
config.setWebServicePort(TEST_PORT); | ||
config.setClusterName("use"); | ||
config.setServiceUrl(pulsar.getWebServiceAddress()); | ||
config.setServiceUrlTls(pulsar.getWebServiceAddressTls()); | ||
service = spy(new WebSocketService(config)); | ||
doReturn(mockZooKeeperClientFactory).when(service).getZooKeeperClientFactory(); | ||
proxyServer = new ProxyServer(config); | ||
WebSocketServiceStarter.start(proxyServer, service); | ||
log.info("Proxy Server Started"); | ||
} | ||
|
||
@AfterClass | ||
protected void cleanup() throws Exception { | ||
super.internalCleanup(); | ||
service.close(); | ||
proxyServer.stop(); | ||
log.info("Finished Cleaning Up Test setup"); | ||
} | ||
|
||
@Test | ||
public void socketTest() throws Exception { | ||
URI consumeUri = URI.create(CONSUME_URI); | ||
URI produceUri = URI.create(PRODUCE_URI); | ||
|
||
WebSocketClient consumeClient = new WebSocketClient(); | ||
SimpleConsumerSocket consumeSocket = new SimpleConsumerSocket(); | ||
WebSocketClient produceClient = new WebSocketClient(); | ||
SimpleProducerSocket produceSocket = new SimpleProducerSocket(); | ||
|
||
try { | ||
consumeClient.start(); | ||
ClientUpgradeRequest consumeRequest = new ClientUpgradeRequest(); | ||
Future<Session> consumerFuture = consumeClient.connect(consumeSocket, consumeUri, consumeRequest); | ||
log.info("Connecting to : {}", consumeUri); | ||
|
||
ClientUpgradeRequest produceRequest = new ClientUpgradeRequest(); | ||
produceClient.start(); | ||
Future<Session> producerFuture = produceClient.connect(produceSocket, produceUri, produceRequest); | ||
// let it connect | ||
Thread.sleep(1000); | ||
Assert.assertTrue(consumerFuture.get().isOpen()); | ||
Assert.assertTrue(producerFuture.get().isOpen()); | ||
|
||
consumeSocket.awaitClose(1, TimeUnit.SECONDS); | ||
produceSocket.awaitClose(1, TimeUnit.SECONDS); | ||
Assert.assertTrue(produceSocket.getBuffer().size() > 0); | ||
Assert.assertEquals(produceSocket.getBuffer(), consumeSocket.getBuffer()); | ||
} finally { | ||
try { | ||
consumeClient.stop(); | ||
produceClient.stop(); | ||
} catch (Exception e) { | ||
log.error(e.getMessage()); | ||
} | ||
} | ||
} | ||
|
||
private static final Logger log = LoggerFactory.getLogger(ProxyPublishConsumeWithoutZKTest.class); | ||
} |
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't we also have
serviceUrl
andserviceUrlTls
here?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, I didn't add it into config to avoid confusion as
serviceUrl
is optional ifglobalZookeeperServers
is already present.We have still kept
clusterName
in config because it is required by Authorization, and proxy fetchesserviceUrl
fromzookeeper
ifglobalZookeeperServers
andclusterName
is present.Do you think, we should still keep
serviceUrl
by providing comment with short description as mentioned above?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed. added
serviceUrl
andserviceUrlTls