-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Pass brokerServiceUrl to websocket service configuration
- Loading branch information
Showing
10 changed files
with
419 additions
and
29 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
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.