use of io.vertx.core.buffer.Buffer in project vert.x by eclipse.
the class NetTest method testCopyClientOptions.
@Test
public void testCopyClientOptions() {
NetClientOptions options = new NetClientOptions();
int sendBufferSize = TestUtils.randomPositiveInt();
int receiverBufferSize = TestUtils.randomPortInt();
Random rand = new Random();
boolean reuseAddress = rand.nextBoolean();
int trafficClass = TestUtils.randomByte() + 128;
boolean tcpNoDelay = rand.nextBoolean();
boolean tcpKeepAlive = rand.nextBoolean();
int soLinger = TestUtils.randomPositiveInt();
boolean usePooledBuffers = rand.nextBoolean();
int idleTimeout = TestUtils.randomPositiveInt();
boolean ssl = rand.nextBoolean();
String hostnameVerificationAlgorithm = TestUtils.randomAlphaString(10);
JksOptions keyStoreOptions = new JksOptions();
String ksPassword = TestUtils.randomAlphaString(100);
keyStoreOptions.setPassword(ksPassword);
JksOptions trustStoreOptions = new JksOptions();
String tsPassword = TestUtils.randomAlphaString(100);
trustStoreOptions.setPassword(tsPassword);
String enabledCipher = TestUtils.randomAlphaString(100);
int connectTimeout = TestUtils.randomPositiveInt();
boolean trustAll = rand.nextBoolean();
String crlPath = TestUtils.randomUnicodeString(100);
Buffer crlValue = TestUtils.randomBuffer(100);
int reconnectAttempts = TestUtils.randomPositiveInt();
long reconnectInterval = TestUtils.randomPositiveInt();
boolean useAlpn = TestUtils.randomBoolean();
boolean openSslSessionCacheEnabled = rand.nextBoolean();
SSLEngineOptions sslEngine = TestUtils.randomBoolean() ? new JdkSSLEngineOptions() : new OpenSSLEngineOptions();
options.setSendBufferSize(sendBufferSize);
options.setReceiveBufferSize(receiverBufferSize);
options.setReuseAddress(reuseAddress);
options.setTrafficClass(trafficClass);
options.setSsl(ssl);
options.setTcpNoDelay(tcpNoDelay);
options.setTcpKeepAlive(tcpKeepAlive);
options.setSoLinger(soLinger);
options.setUsePooledBuffers(usePooledBuffers);
options.setIdleTimeout(idleTimeout);
options.setKeyStoreOptions(keyStoreOptions);
options.setTrustStoreOptions(trustStoreOptions);
options.addEnabledCipherSuite(enabledCipher);
options.setConnectTimeout(connectTimeout);
options.setTrustAll(trustAll);
options.addCrlPath(crlPath);
options.addCrlValue(crlValue);
options.setReconnectAttempts(reconnectAttempts);
options.setReconnectInterval(reconnectInterval);
options.setUseAlpn(useAlpn);
options.setSslEngineOptions(sslEngine);
options.setHostnameVerificationAlgorithm(hostnameVerificationAlgorithm);
NetClientOptions copy = new NetClientOptions(options);
assertEquals(sendBufferSize, copy.getSendBufferSize());
assertEquals(receiverBufferSize, copy.getReceiveBufferSize());
assertEquals(reuseAddress, copy.isReuseAddress());
assertEquals(trafficClass, copy.getTrafficClass());
assertEquals(tcpNoDelay, copy.isTcpNoDelay());
assertEquals(tcpKeepAlive, copy.isTcpKeepAlive());
assertEquals(soLinger, copy.getSoLinger());
assertEquals(usePooledBuffers, copy.isUsePooledBuffers());
assertEquals(idleTimeout, copy.getIdleTimeout());
assertEquals(ssl, copy.isSsl());
assertNotSame(keyStoreOptions, copy.getKeyCertOptions());
assertEquals(ksPassword, ((JksOptions) copy.getKeyCertOptions()).getPassword());
assertNotSame(trustStoreOptions, copy.getTrustOptions());
assertEquals(tsPassword, ((JksOptions) copy.getTrustOptions()).getPassword());
assertEquals(1, copy.getEnabledCipherSuites().size());
assertTrue(copy.getEnabledCipherSuites().contains(enabledCipher));
assertEquals(connectTimeout, copy.getConnectTimeout());
assertEquals(trustAll, copy.isTrustAll());
assertEquals(1, copy.getCrlPaths().size());
assertEquals(crlPath, copy.getCrlPaths().get(0));
assertEquals(1, copy.getCrlValues().size());
assertEquals(crlValue, copy.getCrlValues().get(0));
assertEquals(reconnectAttempts, copy.getReconnectAttempts());
assertEquals(reconnectInterval, copy.getReconnectInterval());
assertEquals(useAlpn, copy.isUseAlpn());
assertEquals(sslEngine, copy.getSslEngineOptions());
assertEquals(hostnameVerificationAlgorithm, copy.getHostnameVerificationAlgorithm());
}
use of io.vertx.core.buffer.Buffer in project vert.x by eclipse.
the class NetTest method testWriteSameBufferMoreThanOnce.
@Test
public void testWriteSameBufferMoreThanOnce() throws Exception {
server.connectHandler(socket -> {
Buffer received = Buffer.buffer();
socket.handler(buff -> {
received.appendBuffer(buff);
if (received.toString().equals("foofoo")) {
testComplete();
}
});
}).listen(ar -> {
assertTrue(ar.succeeded());
client.connect(1234, "localhost", result -> {
NetSocket socket = result.result();
Buffer buff = Buffer.buffer("foo");
socket.write(buff);
socket.write(buff);
});
});
await();
}
use of io.vertx.core.buffer.Buffer in project vert.x by eclipse.
the class NetTest method testCopyServerOptions.
@Test
public void testCopyServerOptions() {
NetServerOptions options = new NetServerOptions();
int sendBufferSize = TestUtils.randomPositiveInt();
int receiverBufferSize = TestUtils.randomPortInt();
Random rand = new Random();
boolean reuseAddress = rand.nextBoolean();
int trafficClass = TestUtils.randomByte() + 128;
boolean tcpNoDelay = rand.nextBoolean();
boolean tcpKeepAlive = rand.nextBoolean();
int soLinger = TestUtils.randomPositiveInt();
boolean usePooledBuffers = rand.nextBoolean();
int idleTimeout = TestUtils.randomPositiveInt();
boolean ssl = rand.nextBoolean();
JksOptions keyStoreOptions = new JksOptions();
String ksPassword = TestUtils.randomAlphaString(100);
keyStoreOptions.setPassword(ksPassword);
JksOptions trustStoreOptions = new JksOptions();
String tsPassword = TestUtils.randomAlphaString(100);
trustStoreOptions.setPassword(tsPassword);
String enabledCipher = TestUtils.randomAlphaString(100);
String crlPath = TestUtils.randomUnicodeString(100);
Buffer crlValue = TestUtils.randomBuffer(100);
int port = 1234;
String host = TestUtils.randomAlphaString(100);
int acceptBacklog = TestUtils.randomPortInt();
boolean useAlpn = TestUtils.randomBoolean();
boolean openSslSessionCacheEnabled = rand.nextBoolean();
SSLEngineOptions sslEngine = TestUtils.randomBoolean() ? new JdkSSLEngineOptions() : new OpenSSLEngineOptions();
options.setSendBufferSize(sendBufferSize);
options.setReceiveBufferSize(receiverBufferSize);
options.setReuseAddress(reuseAddress);
options.setTrafficClass(trafficClass);
options.setTcpNoDelay(tcpNoDelay);
options.setTcpKeepAlive(tcpKeepAlive);
options.setSoLinger(soLinger);
options.setUsePooledBuffers(usePooledBuffers);
options.setIdleTimeout(idleTimeout);
options.setSsl(ssl);
options.setKeyStoreOptions(keyStoreOptions);
options.setTrustStoreOptions(trustStoreOptions);
options.addEnabledCipherSuite(enabledCipher);
options.addCrlPath(crlPath);
options.addCrlValue(crlValue);
options.setPort(port);
options.setHost(host);
options.setAcceptBacklog(acceptBacklog);
options.setUseAlpn(useAlpn);
options.setSslEngineOptions(sslEngine);
NetServerOptions copy = new NetServerOptions(options);
assertEquals(sendBufferSize, copy.getSendBufferSize());
assertEquals(receiverBufferSize, copy.getReceiveBufferSize());
assertEquals(reuseAddress, copy.isReuseAddress());
assertEquals(trafficClass, copy.getTrafficClass());
assertEquals(tcpNoDelay, copy.isTcpNoDelay());
assertEquals(tcpKeepAlive, copy.isTcpKeepAlive());
assertEquals(soLinger, copy.getSoLinger());
assertEquals(usePooledBuffers, copy.isUsePooledBuffers());
assertEquals(idleTimeout, copy.getIdleTimeout());
assertEquals(ssl, copy.isSsl());
assertNotSame(keyStoreOptions, copy.getKeyCertOptions());
assertEquals(ksPassword, ((JksOptions) copy.getKeyCertOptions()).getPassword());
assertNotSame(trustStoreOptions, copy.getTrustOptions());
assertEquals(tsPassword, ((JksOptions) copy.getTrustOptions()).getPassword());
assertEquals(1, copy.getEnabledCipherSuites().size());
assertTrue(copy.getEnabledCipherSuites().contains(enabledCipher));
assertEquals(1, copy.getCrlPaths().size());
assertEquals(crlPath, copy.getCrlPaths().get(0));
assertEquals(1, copy.getCrlValues().size());
assertEquals(crlValue, copy.getCrlValues().get(0));
assertEquals(port, copy.getPort());
assertEquals(host, copy.getHost());
assertEquals(acceptBacklog, copy.getAcceptBacklog());
assertEquals(useAlpn, copy.isUseAlpn());
assertEquals(sslEngine, copy.getSslEngineOptions());
}
use of io.vertx.core.buffer.Buffer in project vert.x by eclipse.
the class NetTest method setHandlers.
void setHandlers(NetSocket sock) {
Handler<Message<Buffer>> resumeHandler = m -> sock.resume();
MessageConsumer reg = vertx.eventBus().<Buffer>consumer("client_resume").handler(resumeHandler);
sock.closeHandler(v -> reg.unregister());
}
use of io.vertx.core.buffer.Buffer in project vert.x by eclipse.
the class RecordParserTest method testIllegalArguments.
@Test
public void testIllegalArguments() throws Exception {
assertNullPointerException(() -> RecordParser.newDelimited((Buffer) null, handler -> {
}));
assertNullPointerException(() -> RecordParser.newDelimited((String) null, handler -> {
}));
RecordParser parser = RecordParser.newDelimited("", handler -> {
});
assertNullPointerException(() -> parser.setOutput(null));
assertNullPointerException(() -> parser.delimitedMode((Buffer) null));
assertNullPointerException(() -> parser.delimitedMode((String) null));
}
Aggregations