use of com.google.cloud.video.livestream.v1.Channel in project jboss-remoting by jboss-remoting.
the class ChannelTestBase method testSeveralWriteMessage.
@Test
public void testSeveralWriteMessage() throws Exception {
final AtomicBoolean wasEmpty = new AtomicBoolean();
final AtomicReference<IOException> exRef = new AtomicReference<IOException>();
final CountDownLatch latch = new CountDownLatch(50);
final AtomicInteger count = new AtomicInteger();
recvChannel.receiveMessage(new Channel.Receiver() {
public void handleError(final Channel channel, final IOException error) {
error.printStackTrace();
exRef.set(error);
latch.countDown();
}
public void handleEnd(final Channel channel) {
System.out.println("End of channel");
latch.countDown();
}
public void handleMessage(final Channel channel, final MessageInputStream message) {
System.out.println("Message received");
try {
if (message.read() == -1) {
wasEmpty.set(true);
}
message.close();
} catch (IOException e) {
exRef.set(e);
} finally {
IoUtils.safeClose(message);
latch.countDown();
if (count.getAndIncrement() < 50) {
recvChannel.receiveMessage(this);
}
}
}
});
for (int i = 0; i < 50; i++) {
MessageOutputStream messageOutputStream = sendChannel.writeMessage();
messageOutputStream.close();
// close should be idempotent
messageOutputStream.close();
// no effect expected, since message is closed
messageOutputStream.flush();
}
latch.await();
IOException exception = exRef.get();
if (exception != null) {
throw exception;
}
assertTrue(wasEmpty.get());
}
use of com.google.cloud.video.livestream.v1.Channel in project jboss-remoting by jboss-remoting.
the class ConnectionTestCase method testManyChannelsLotsOfData.
@Test
@Ignore
public void testManyChannelsLotsOfData() throws Exception {
final XnioWorker clientWorker = clientEndpoint.getXnioWorker();
final XnioWorker serverWorker = serverEndpoint.getXnioWorker();
final Queue<Throwable> problems = new ConcurrentLinkedQueue<Throwable>();
final CountDownLatch serverChannelCount = new CountDownLatch(CHANNEL_COUNT * CONNECTION_COUNT);
final CountDownLatch clientChannelCount = new CountDownLatch(CHANNEL_COUNT * CONNECTION_COUNT);
serverEndpoint.registerService("test", new OpenListener() {
public void channelOpened(final Channel channel) {
channel.receiveMessage(new Channel.Receiver() {
public void handleError(final Channel channel, final IOException error) {
problems.add(error);
error.printStackTrace();
serverChannelCount.countDown();
}
public void handleEnd(final Channel channel) {
serverChannelCount.countDown();
}
public void handleMessage(final Channel channel, final MessageInputStream message) {
try {
channel.receiveMessage(this);
while (message.read(junkBuffer) > -1) ;
} catch (Exception e) {
e.printStackTrace();
problems.add(e);
} finally {
IoUtils.safeClose(message);
}
}
});
}
public void registrationTerminated() {
}
}, OptionMap.EMPTY);
final AtomicReferenceArray<Connection> connections = new AtomicReferenceArray<Connection>(CONNECTION_COUNT);
for (int h = 0; h < CONNECTION_COUNT; h++) {
IoFuture<Connection> futureConnection = AuthenticationContext.empty().with(MatchRule.ALL, AuthenticationConfiguration.empty().useName("bob").usePassword("pass").setSaslMechanismSelector(SaslMechanismSelector.NONE.addMechanism("SCRAM-SHA-256"))).run(new PrivilegedAction<IoFuture<Connection>>() {
public IoFuture<Connection> run() {
try {
return clientEndpoint.connect(new URI("remote://localhost:30123"), OptionMap.EMPTY);
} catch (URISyntaxException e) {
throw new RuntimeException(e);
}
}
});
final Connection connection = futureConnection.get();
connections.set(h, connection);
for (int i = 0; i < CHANNEL_COUNT; i++) {
clientWorker.execute(new Runnable() {
public void run() {
final Random random = new Random();
final IoFuture<Channel> future = connection.openChannel("test", OptionMap.EMPTY);
try {
final Channel channel = future.get();
try {
final byte[] bytes = new byte[BUFFER_SIZE];
for (int j = 0; j < MESSAGE_COUNT; j++) {
final MessageOutputStream stream = channel.writeMessage();
try {
for (int k = 0; k < 100; k++) {
random.nextBytes(bytes);
stream.write(bytes, 0, random.nextInt(BUFFER_SIZE - 1) + 1);
}
stream.close();
} finally {
IoUtils.safeClose(stream);
}
stream.close();
}
} finally {
IoUtils.safeClose(channel);
}
} catch (IOException e) {
e.printStackTrace();
problems.add(e);
} finally {
clientChannelCount.countDown();
}
}
});
}
}
Thread.sleep(500);
serverChannelCount.await();
clientChannelCount.await();
for (int h = 0; h < CONNECTION_COUNT; h++) {
connections.get(h).close();
}
assertArrayEquals(new Object[0], problems.toArray());
}
use of com.google.cloud.video.livestream.v1.Channel in project jboss-remoting by jboss-remoting.
the class ConnectionTestCase method testChannelOptions.
@Test
public void testChannelOptions() throws Exception {
serverEndpoint.registerService("test", new OpenListener() {
@Override
public void channelOpened(Channel channel) {
//
Assert.assertTrue(channel.getOption(RemotingOptions.RECEIVE_WINDOW_SIZE) <= MAX_SERVER_RECEIVE);
Assert.assertTrue(channel.getOption(RemotingOptions.TRANSMIT_WINDOW_SIZE) <= MAX_SERVER_TRANSMIT);
}
@Override
public void registrationTerminated() {
//
}
}, OptionMap.create(RemotingOptions.RECEIVE_WINDOW_SIZE, MAX_SERVER_RECEIVE, RemotingOptions.TRANSMIT_WINDOW_SIZE, MAX_SERVER_TRANSMIT));
final Connection connection = AuthenticationContext.empty().with(MatchRule.ALL, AuthenticationConfiguration.empty().useName("bob").usePassword("pass").setSaslMechanismSelector(SaslMechanismSelector.NONE.addMechanism("SCRAM-SHA-256"))).run(new PrivilegedAction<Connection>() {
public Connection run() {
try {
return clientEndpoint.connect(new URI("remote://localhost:30123"), OptionMap.EMPTY).get();
} catch (IOException | URISyntaxException e) {
throw new RuntimeException(e);
}
}
});
IoFuture<Channel> future = connection.openChannel("test", OptionMap.create(RemotingOptions.RECEIVE_WINDOW_SIZE, 0x8000, RemotingOptions.TRANSMIT_WINDOW_SIZE, 0x12000));
Channel channel = future.get();
try {
Assert.assertEquals("transmit", 0x12000, (int) channel.getOption(RemotingOptions.TRANSMIT_WINDOW_SIZE));
Assert.assertEquals("receive", 0x8000, (int) channel.getOption(RemotingOptions.RECEIVE_WINDOW_SIZE));
} finally {
if (channel != null) {
channel.close();
}
}
future = connection.openChannel("test", OptionMap.create(RemotingOptions.RECEIVE_WINDOW_SIZE, 0x24000, RemotingOptions.TRANSMIT_WINDOW_SIZE, 0x24000));
channel = future.get();
try {
Assert.assertEquals("transmit", MAX_SERVER_RECEIVE, (int) channel.getOption(RemotingOptions.TRANSMIT_WINDOW_SIZE));
Assert.assertEquals("receive", MAX_SERVER_TRANSMIT, (int) channel.getOption(RemotingOptions.RECEIVE_WINDOW_SIZE));
} finally {
if (channel != null) {
channel.close();
}
}
}
use of com.google.cloud.video.livestream.v1.Channel in project jboss-remoting by jboss-remoting.
the class OutboundMessageCountTestCase method testOutboundMessageSend.
/**
* Tests that multiple threads opening and closing a message on the channel doesn't cause the JBoss Remoting
* code to get out of sync with the current outbound message count it maintains.
*
* @throws Exception
*/
@Test
public void testOutboundMessageSend() throws Exception {
serverChannel.receiveMessage(new Channel.Receiver() {
public void handleError(final Channel channel, final IOException error) {
}
public void handleEnd(final Channel channel) {
}
public void handleMessage(final Channel channel, final MessageInputStream message) {
channel.receiveMessage(this);
try {
while (message.read() != -1) ;
} catch (IOException ignored) {
} finally {
safeClose(message);
}
}
});
final int NUM_THREADS = 150;
final ExecutorService executorService = Executors.newFixedThreadPool(NUM_THREADS);
final Future<Throwable>[] futureFailures = new Future[NUM_THREADS];
final Semaphore semaphore = new Semaphore(MAX_OUTBOUND_MESSAGES, true);
try {
// create and submit the tasks which will send out the messages
for (int i = 0; i < NUM_THREADS; i++) {
futureFailures[i] = executorService.submit(new MessageSender(this.clientChannel, semaphore));
}
int failureCount = 0;
// wait for the tasks to complete and then collect any failures
for (int i = 0; i < NUM_THREADS; i++) {
final Throwable failure = futureFailures[i].get();
if (failure == null) {
continue;
}
failureCount++;
logger.info("Thread#" + i + " failed with exception", failure);
}
Assert.assertEquals("Some threads failed to send message on the channel", 0, failureCount);
} finally {
executorService.shutdown();
}
}
use of com.google.cloud.video.livestream.v1.Channel in project jboss-remoting by jboss-remoting.
the class OutboundMessageCountTestCase method beforeTest.
@Before
public void beforeTest() throws IOException, URISyntaxException, InterruptedException {
System.gc();
System.runFinalization();
Logger.getLogger("TEST").infof("Running test %s", name.getMethodName());
final FutureResult<Channel> passer = new FutureResult<Channel>();
serviceRegistration = endpoint.registerService("org.jboss.test", new OpenListener() {
public void channelOpened(final Channel channel) {
passer.setResult(channel);
}
public void registrationTerminated() {
}
}, OptionMap.EMPTY);
IoFuture<Connection> futureConnection = AuthenticationContext.empty().with(MatchRule.ALL, AuthenticationConfiguration.empty().useName("bob").usePassword("pass").setSaslMechanismSelector(SaslMechanismSelector.NONE.addMechanism("SCRAM-SHA-256"))).run(new PrivilegedAction<IoFuture<Connection>>() {
public IoFuture<Connection> run() {
try {
return endpoint.connect(new URI("remote://[::1]:30123"), OptionMap.EMPTY);
} catch (URISyntaxException e) {
throw new RuntimeException(e);
}
}
});
connection = futureConnection.get();
final OptionMap channelCreationOptions = OptionMap.create(RemotingOptions.MAX_OUTBOUND_MESSAGES, MAX_OUTBOUND_MESSAGES);
IoFuture<Channel> futureChannel = connection.openChannel("org.jboss.test", channelCreationOptions);
clientChannel = futureChannel.get();
serverChannel = passer.getIoFuture().get();
assertNotNull(serverChannel);
}
Aggregations