protected static Map<String, String> genMap(int num) { Map<String, String> map = new HashMap<>(); for (int i = 0; i < num; i++) { String key; do { key = TestUtils.randomAlphaString(1 + (int) ((19) * Math.random())).toLowerCase(); } while (map.containsKey(key)); map.put(key, TestUtils.randomAlphaString(1 + (int) ((19) * Math.random()))); } return map; }
/** * Creates a Buffer of random bytes. * * @param length The length of the Buffer * @return the Buffer */ public static Buffer randomBuffer(int length) { return randomBuffer(length, false, (byte) 0); }
@Test public void testSendJsonArray() { JsonArray arr = new JsonArray(); arr.add(TestUtils.randomUnicodeString(100)).add(TestUtils.randomInt()).add(TestUtils.randomBoolean()); testSend(arr, (received) -> { assertEquals(arr, received); assertFalse(arr == received); // Make sure it's copied }); }
@Override public void setUp() throws Exception { super.setUp(); randType = TestUtils.randomElement(ProxyType.values()); randHost = TestUtils.randomAlphaString(10); randPort = TestUtils.randomPortInt(); randUsername = TestUtils.randomAlphaString(10); randPassword = TestUtils.randomAlphaString(10); }
@Test public void testReplyJsonObject() { JsonObject obj = new JsonObject(); obj.put(TestUtils.randomUnicodeString(100), TestUtils.randomUnicodeString(100)).put(TestUtils.randomUnicodeString(100), TestUtils.randomInt()); testReply(obj, (received) -> { assertEquals(obj, received); assertFalse(obj == received); // Make sure it's copied }); }
private void testSetBytesString(Buffer buff) throws Exception { String str = TestUtils.randomUnicodeString(100); buff.setString(50, str); byte[] b1 = buff.getBytes(50, buff.length()); String str2 = new String(b1, "UTF-8"); assertEquals(str, str2); assertNullPointerException(() -> Buffer.buffer(150).setString(0, null)); assertNullPointerException(() -> Buffer.buffer(150).setString(0, null, "UTF-8")); //TODO setString with encoding }
@Test public void testClientOptionsJson() { 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); String ksPath = TestUtils.randomAlphaString(100); keyStoreOptions.setPath(ksPath); JksOptions trustStoreOptions = new JksOptions(); String tsPassword = TestUtils.randomAlphaString(100); trustStoreOptions.setPassword(tsPassword); String tsPath = TestUtils.randomAlphaString(100); trustStoreOptions.setPath(tsPath); String enabledCipher = TestUtils.randomAlphaString(100); int connectTimeout = TestUtils.randomPositiveInt(); boolean trustAll = rand.nextBoolean(); String crlPath = TestUtils.randomUnicodeString(100); int reconnectAttempts = TestUtils.randomPositiveInt(); long reconnectInterval = TestUtils.randomPositiveInt(); boolean useAlpn = TestUtils.randomBoolean();
@Test public void testCopyClientOptions() { HttpClientOptions options = new HttpClientOptions(); 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(); 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();
@Test public void testServerOptionsJson() { 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); String ksPath = TestUtils.randomAlphaString(100); keyStoreOptions.setPath(ksPath); JksOptions trustStoreOptions = new JksOptions(); String tsPassword = TestUtils.randomAlphaString(100); trustStoreOptions.setPassword(tsPassword); String tsPath = TestUtils.randomAlphaString(100); trustStoreOptions.setPath(tsPath); String enabledCipher = TestUtils.randomAlphaString(100); String crlPath = TestUtils.randomUnicodeString(100); int port = 1234; String host = TestUtils.randomAlphaString(100); int acceptBacklog = TestUtils.randomPortInt(); boolean compressionSupported = rand.nextBoolean(); int maxWebsocketFrameSize = TestUtils.randomPositiveInt();
@Test public void testClientOptionsJson() { 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); String ksPath = TestUtils.randomAlphaString(100); keyStoreOptions.setPath(ksPath); JksOptions trustStoreOptions = new JksOptions(); String tsPassword = TestUtils.randomAlphaString(100); trustStoreOptions.setPassword(tsPassword); String tsPath = TestUtils.randomAlphaString(100); trustStoreOptions.setPath(tsPath); String enabledCipher = TestUtils.randomAlphaString(100); int connectTimeout = TestUtils.randomPositiveInt(); boolean trustAll = rand.nextBoolean(); String crlPath = TestUtils.randomUnicodeString(100); boolean verifyHost = rand.nextBoolean(); int maxPoolSize = TestUtils.randomPositiveInt(); boolean keepAlive = rand.nextBoolean();
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; }
@Test public void testSlice1() throws Exception { Buffer buff = TestUtils.randomBuffer(100); Buffer sliced = buff.slice(); assertEquals(buff, sliced); long rand = TestUtils.randomLong(); sliced.setLong(0, rand); assertEquals(rand, buff.getLong(0)); buff.appendString(TestUtils.randomUnicodeString(100)); assertEquals(100, sliced.length()); }
assertEquals(TimeUnit.NANOSECONDS, options.getWarningExceptionTimeUnit()); assertEquals(TimeUnit.MILLISECONDS, options.getBlockedThreadCheckIntervalUnit()); int clusterPort = TestUtils.randomPortInt(); int clusterPublicPort = TestUtils.randomPortInt(); 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(); int proxyOperationTimeout = TestUtils.randomPositiveInt(); long warningExceptionTime = TestUtils.randomPositiveLong(); Random rand = new Random(); boolean haEnabled = rand.nextBoolean(); boolean fileResolverCachingEnabled = rand.nextBoolean(); int quorumSize = TestUtils.randomShort() + 1; String haGroup = TestUtils.randomAlphaString(100); boolean classPathResolvingEnabled = rand.nextBoolean(); boolean metricsEnabled = rand.nextBoolean(); boolean jmxEnabled = rand.nextBoolean(); String jmxDomain = TestUtils.randomAlphaString(100); TimeUnit maxEventLoopExecuteTimeUnit = TimeUnit.SECONDS; TimeUnit maxWorkerExecuteTimeUnit = TimeUnit.MILLISECONDS;
@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(); }
boolean worker = rand.nextBoolean(); boolean multiThreaded = rand.nextBoolean(); String isolationGroup = TestUtils.randomAlphaString(100); boolean ha = rand.nextBoolean(); List<String> cp = Arrays.asList("foo", "bar"); 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; JsonObject json = new JsonObject();
assertTrue(options.isWorker()); assertNull(options.getIsolationGroup()); String rand = TestUtils.randomUnicodeString(1000); assertEquals(options, options.setIsolationGroup(rand)); assertEquals(rand, options.getIsolationGroup()); assertEquals(options, options.setIsolatedClasses(isol)); assertSame(isol, options.getIsolatedClasses()); String workerPoolName = TestUtils.randomAlphaString(10); assertEquals(options, options.setWorkerPoolName(workerPoolName)); assertEquals(workerPoolName, options.getWorkerPoolName()); int workerPoolSize = TestUtils.randomPositiveInt(); assertEquals(options, options.setWorkerPoolSize(workerPoolSize)); assertEquals(workerPoolSize, options.getWorkerPoolSize()); long maxWorkerExecuteTime = TestUtils.randomPositiveLong(); assertEquals(options, options.setMaxWorkerExecuteTime(maxWorkerExecuteTime)); assertEquals(maxWorkerExecuteTime, options.getMaxWorkerExecuteTime());
assertEquals(AddressResolverOptions.DEFAULT_SEACH_DOMAINS, options.getSearchDomains()); boolean optResourceEnabled = TestUtils.randomBoolean(); List<String> servers = Arrays.asList("1.2.3.4", "5.6.7.8"); int minTTL = TestUtils.randomPositiveInt(); int maxTTL = minTTL + 1000; int negativeTTL = TestUtils.randomPositiveInt(); int queryTimeout = 1 + TestUtils.randomPositiveInt(); int maxQueries = 1 + TestUtils.randomPositiveInt(); boolean rdFlag = TestUtils.randomBoolean(); int ndots = TestUtils.randomPositiveInt() - 2; List<String> searchDomains = new ArrayList<>(); for (int i = 0; i < 2; i++) { searchDomains.add(TestUtils.randomAlphaString(15));
@Test public void createAndCopy() { Option option = new Option() .setArgName(TestUtils.randomAlphaString(100)) .addChoice(TestUtils.randomAlphaString(100)) .setDefaultValue(TestUtils.randomAlphaString(100)) .setDescription(TestUtils.randomAlphaString(100)) .setFlag(TestUtils.randomBoolean()) .setHelp(TestUtils.randomBoolean()) .setHidden(TestUtils.randomBoolean()) .setLongName(TestUtils.randomAlphaString(100)) .setMultiValued(TestUtils.randomBoolean()) .setRequired(TestUtils.randomBoolean()) .setShortName(TestUtils.randomAlphaString(100)) .setSingleValued(TestUtils.randomBoolean());
@Test public void testPublishString() { String str = TestUtils.randomUnicodeString(100); testPublish(str); }
/** * 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; }