public static <E> E randomElement(E[] array) { return array[randomPositiveInt() % array.length]; }
public static <E extends Enum<E>> Set<E> randomEnumSet(Class<E> enumType) { EnumSet<E> set = EnumSet.noneOf(enumType); for (E e : EnumSet.allOf(enumType)) { if (randomPositiveInt() % 2 == 1) { set.add(e); } } return set; }
@Test public void testCopyOptionsJson() { Random rand = new Random(); boolean broadcast = rand.nextBoolean(); boolean loopbackModeDisabled = rand.nextBoolean(); int multicastTimeToLive = TestUtils.randomPositiveInt(); String multicastNetworkInterface = TestUtils.randomAlphaString(100); boolean reuseAddress = rand.nextBoolean(); boolean ipV6 = rand.nextBoolean(); JsonObject json = new JsonObject().put("broadcast", broadcast) .put("loopbackModeDisabled", loopbackModeDisabled) .put("multicastTimeToLive", multicastTimeToLive) .put("multicastNetworkInterface", multicastNetworkInterface) .put("reuseAddress", reuseAddress) .put("ipV6", ipV6); DatagramSocketOptions copy = new DatagramSocketOptions(json); assertEquals(broadcast, copy.isBroadcast()); assertEquals(loopbackModeDisabled, copy.isLoopbackModeDisabled()); assertEquals(multicastTimeToLive, copy.getMulticastTimeToLive()); assertEquals(multicastNetworkInterface, copy.getMulticastNetworkInterface()); assertEquals(reuseAddress, copy.isReuseAddress()); assertEquals(ipV6, copy.isIpV6()); testComplete(); }
List<String> isol = Arrays.asList("com.foo.MyClass", "org.foo.*"); String poolName = TestUtils.randomAlphaString(10); int poolSize = TestUtils.randomPositiveInt(); long maxWorkerExecuteTime = TestUtils.randomPositiveLong(); TimeUnit maxWorkerExecuteTimeUnit = TimeUnit.MILLISECONDS;
/** * Create random {@link Http2Settings} with valid values. * * @return the random settings */ public static Http2Settings randomHttp2Settings() { long headerTableSize = 10 + randomPositiveInt() % (Http2CodecUtil.MAX_HEADER_TABLE_SIZE - 10); boolean enablePush = randomBoolean(); long maxConcurrentStreams = 10 + randomPositiveLong() % (Http2CodecUtil.MAX_CONCURRENT_STREAMS - 10); int initialWindowSize = 10 + randomPositiveInt() % (Http2CodecUtil.MAX_INITIAL_WINDOW_SIZE - 10); int maxFrameSize = Http2CodecUtil.MAX_FRAME_SIZE_LOWER_BOUND + randomPositiveInt() % (Http2CodecUtil.MAX_FRAME_SIZE_UPPER_BOUND - Http2CodecUtil.MAX_FRAME_SIZE_LOWER_BOUND); long maxHeaderListSize = 10 + randomPositiveLong() % (Http2CodecUtil.MAX_HEADER_LIST_SIZE - 10); Http2Settings settings = new Http2Settings(); settings.setHeaderTableSize(headerTableSize); settings.setPushEnabled(enablePush); settings.setMaxConcurrentStreams(maxConcurrentStreams); settings.setInitialWindowSize(initialWindowSize); settings.setMaxFrameSize(maxFrameSize); settings.setMaxHeaderListSize(maxHeaderListSize); settings.set('\u0007', (randomPositiveLong() & 0xFFFFFFFFL)); return settings; }
@Test public void testCopyClientOptions() { HttpClientOptions options = new HttpClientOptions(); int sendBufferSize = TestUtils.randomPositiveInt(); int receiverBufferSize = TestUtils.randomPortInt(); Random rand = new Random(); boolean tcpNoDelay = rand.nextBoolean(); boolean tcpKeepAlive = rand.nextBoolean(); int soLinger = TestUtils.randomPositiveInt(); boolean usePooledBuffers = rand.nextBoolean(); int idleTimeout = TestUtils.randomPositiveInt(); boolean ssl = rand.nextBoolean(); KeyCertOptions keyCertOptions = randomKeyCertOptions(); TrustOptions trustOptions = randomTrustOptions(); String enabledCipher = TestUtils.randomAlphaString(100); int connectTimeout = TestUtils.randomPositiveInt(); boolean trustAll = rand.nextBoolean(); String crlPath = TestUtils.randomUnicodeString(100); Buffer crlValue = TestUtils.randomBuffer(100); int keepAliveTimeout = TestUtils.randomPositiveInt(); int http2KeepAliveTimeout = TestUtils.randomPositiveInt(); int maxPoolSize = TestUtils.randomPositiveInt(); boolean keepAlive = rand.nextBoolean(); boolean pipelining = rand.nextBoolean(); int pipeliningLimit = TestUtils.randomPositiveInt(); int http2MaxPoolSize = TestUtils.randomPositiveInt(); int http2MultiplexingLimit = TestUtils.randomPositiveInt(); int http2ConnectionWindowSize = TestUtils.randomPositiveInt();
Deque<Object> received = new ArrayDeque<>(); so.messageHandler(received::add); int status = 4000 + TestUtils.randomPositiveInt() % 100; String reason = TestUtils.randomAlphaString(10); so.writeMessage(new CloseWebSocketFrame(status, reason));
so.channelHandlerContext().pipeline().addBefore("handler", "encoder", new WebSocket13FrameEncoder(true)); so.channelHandlerContext().pipeline().addBefore("handler", "decoder", new WebSocket13FrameDecoder(false, false, 1000)); int status = 4000 + TestUtils.randomPositiveInt() % 100; String reason = TestUtils.randomAlphaString(10); so.writeMessage(new CloseWebSocketFrame(status, reason));
@Test public void testCopyServerOptions() { HttpServerOptions options = new HttpServerOptions(); int sendBufferSize = TestUtils.randomPositiveInt(); int receiverBufferSize = TestUtils.randomPortInt(); Random rand = new Random(); boolean tcpNoDelay = rand.nextBoolean(); boolean tcpKeepAlive = rand.nextBoolean(); int soLinger = TestUtils.randomPositiveInt(); boolean usePooledBuffers = rand.nextBoolean(); int idleTimeout = TestUtils.randomPositiveInt(); boolean ssl = rand.nextBoolean(); KeyCertOptions keyCertOptions = randomKeyCertOptions(); int acceptBacklog = TestUtils.randomPortInt(); boolean compressionSupported = rand.nextBoolean(); int maxWebsocketFrameSize = TestUtils.randomPositiveInt(); String wsSubProtocol = TestUtils.randomAlphaString(10); boolean is100ContinueHandledAutomatically = rand.nextBoolean(); boolean openSslSessionCacheEnabled = rand.nextBoolean(); SSLEngineOptions sslEngine = TestUtils.randomBoolean() ? new JdkSSLEngineOptions() : new OpenSSLEngineOptions(); List<HttpVersion> alpnVersions = Collections.singletonList(HttpVersion.values()[TestUtils.randomPositiveInt() % 3]); boolean decompressionSupported = rand.nextBoolean(); boolean acceptUnmaskedFrames = rand.nextBoolean(); int decoderInitialBufferSize = TestUtils.randomPositiveInt();
@Test public void testCopyOptions() { DatagramSocketOptions options = new DatagramSocketOptions(); Random rand = new Random(); boolean broadcast = rand.nextBoolean(); boolean loopbackModeDisabled = rand.nextBoolean(); int multicastTimeToLive = TestUtils.randomPositiveInt(); String multicastNetworkInterface = TestUtils.randomAlphaString(100); boolean reuseAddress = rand.nextBoolean(); boolean ipV6 = rand.nextBoolean(); options.setBroadcast(broadcast); options.setLoopbackModeDisabled(loopbackModeDisabled); options.setMulticastTimeToLive(multicastTimeToLive); options.setMulticastNetworkInterface(multicastNetworkInterface); options.setReuseAddress(reuseAddress); options.setIpV6(ipV6); DatagramSocketOptions copy = new DatagramSocketOptions(options); assertEquals(broadcast, copy.isBroadcast()); assertEquals(loopbackModeDisabled, copy.isLoopbackModeDisabled()); assertEquals(multicastTimeToLive, copy.getMulticastTimeToLive()); assertEquals(multicastNetworkInterface, copy.getMulticastNetworkInterface()); assertEquals(reuseAddress, copy.isReuseAddress()); assertEquals(ipV6, copy.isIpV6()); testComplete(); }
public static TrustOptions randomTrustOptions() { TrustOptions trustOptions; switch (TestUtils.randomPositiveInt() % 3) { case 0: trustOptions = new JksOptions(); String tsPassword = TestUtils.randomAlphaString(100); ((JksOptions) trustOptions).setPassword(tsPassword); break; case 1: trustOptions = new PemTrustOptions(); Buffer keyValue = TestUtils.randomBuffer(100); ((PemTrustOptions) trustOptions).addCertValue(keyValue); break; default: trustOptions = new PfxOptions(); String pfxPassword = TestUtils.randomAlphaString(100); ((PfxOptions) trustOptions).setPassword(pfxPassword); } return trustOptions; }
public static KeyCertOptions randomKeyCertOptions() { KeyCertOptions keyCertOptions; switch (TestUtils.randomPositiveInt() % 3) { case 0: keyCertOptions = new JksOptions(); String jksPassword = TestUtils.randomAlphaString(100); ((JksOptions) keyCertOptions).setPassword(jksPassword); break; case 1: keyCertOptions = new PemKeyCertOptions(); Buffer keyValue = TestUtils.randomBuffer(100); ((PemKeyCertOptions) keyCertOptions).setKeyValue(keyValue); break; default: keyCertOptions = new PfxOptions(); String pfxPassword = TestUtils.randomAlphaString(100); ((PfxOptions) keyCertOptions).setPassword(pfxPassword); } return keyCertOptions; }
List<String> isol = Arrays.asList("com.foo.MyClass", "org.foo.*"); String poolName = TestUtils.randomAlphaString(10); int poolSize = TestUtils.randomPositiveInt(); long maxWorkerExecuteTime = TestUtils.randomPositiveLong(); TimeUnit maxWorkerExecuteTimeUnit = TimeUnit.MILLISECONDS;
List<String> isol = Arrays.asList("com.foo.MyClass", "org.foo.*"); String poolName = TestUtils.randomAlphaString(10); int poolSize = TestUtils.randomPositiveInt(); long maxWorkerExecuteTime = TestUtils.randomPositiveLong(); TimeUnit maxWorkerExecuteTimeUnit = TimeUnit.MILLISECONDS;
@Test public void testCopyClientOptions() { NetClientOptions options = new NetClientOptions(); int sendBufferSize = TestUtils.randomPositiveInt(); int receiverBufferSize = TestUtils.randomPortInt(); Random rand = new Random(); 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); 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();
int eventLoopPoolSize = TestUtils.randomPositiveInt(); int internalBlockingPoolSize = TestUtils.randomPositiveInt(); int workerPoolSize = TestUtils.randomPositiveInt(); int blockedThreadCheckInterval = TestUtils.randomPositiveInt(); String clusterHost = TestUtils.randomAlphaString(100); String clusterPublicHost = TestUtils.randomAlphaString(100); long clusterPingInterval = TestUtils.randomPositiveLong(); long clusterPingReplyInterval = TestUtils.randomPositiveLong(); int maxEventLoopExecuteTime = TestUtils.randomPositiveInt(); int maxWorkerExecuteTime = TestUtils.randomPositiveInt(); Random rand = new Random(); boolean haEnabled = rand.nextBoolean();
assertEquals(options, options.setWorkerPoolName(workerPoolName)); assertEquals(workerPoolName, options.getWorkerPoolName()); int workerPoolSize = TestUtils.randomPositiveInt(); assertEquals(options, options.setWorkerPoolSize(workerPoolSize)); assertEquals(workerPoolSize, options.getWorkerPoolSize());
@Test public void testCopyServerOptions() { NetServerOptions options = new NetServerOptions(); int sendBufferSize = TestUtils.randomPositiveInt(); int receiverBufferSize = TestUtils.randomPortInt(); Random rand = new Random(); 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();
int rand = TestUtils.randomPositiveInt(); assertEquals(options, options.setSendBufferSize(rand)); assertEquals(rand, options.getSendBufferSize()); rand = TestUtils.randomPositiveInt(); assertEquals(options, options.setReceiveBufferSize(rand)); assertEquals(rand, options.getReceiveBufferSize()); rand = TestUtils.randomPositiveInt(); assertEquals(options, options.setSoLinger(rand)); assertEquals(rand, options.getSoLinger()); assertTrue(options.isUsePooledBuffers()); rand = TestUtils.randomPositiveInt(); assertEquals(0, options.getIdleTimeout()); assertEquals(options, options.setIdleTimeout(rand)); rand = TestUtils.randomPositiveInt(); assertEquals(options, options.setReconnectAttempts(rand)); assertEquals(rand, options.getReconnectAttempts()); rand = TestUtils.randomPositiveInt(); assertEquals(options, options.setReconnectInterval(rand)); assertEquals(rand, options.getReconnectInterval());
DatagramSocketOptions options = new DatagramSocketOptions(); assertEquals(NetworkOptions.DEFAULT_SEND_BUFFER_SIZE, options.getSendBufferSize()); int rand = TestUtils.randomPositiveInt(); assertEquals(options, options.setSendBufferSize(rand)); assertEquals(rand, options.getSendBufferSize()); rand = TestUtils.randomPositiveInt(); assertEquals(options, options.setReceiveBufferSize(rand)); assertEquals(rand, options.getReceiveBufferSize()); rand = TestUtils.randomPositiveInt(); assertEquals(options, options.setMulticastTimeToLive(rand)); assertEquals(rand, options.getMulticastTimeToLive());