本文整理汇总了Java中org.apache.kafka.test.TestUtils.randomString方法的典型用法代码示例。如果您正苦于以下问题:Java TestUtils.randomString方法的具体用法?Java TestUtils.randomString怎么用?Java TestUtils.randomString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.kafka.test.TestUtils
的用法示例。
在下文中一共展示了TestUtils.randomString方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: checkClientConnection
import org.apache.kafka.test.TestUtils; //导入方法依赖的package包/类
public static void checkClientConnection(Selector selector, String node, int minMessageSize, int messageCount) throws Exception {
waitForChannelReady(selector, node);
String prefix = TestUtils.randomString(minMessageSize);
int requests = 0;
int responses = 0;
selector.send(new NetworkSend(node, ByteBuffer.wrap((prefix + "-0").getBytes())));
requests++;
while (responses < messageCount) {
selector.poll(0L);
assertEquals("No disconnects should have occurred.", 0, selector.disconnected().size());
for (NetworkReceive receive : selector.completedReceives()) {
assertEquals(prefix + "-" + responses, new String(Utils.toArray(receive.payload())));
responses++;
}
for (int i = 0; i < selector.completedSends().size() && requests < messageCount && selector.isChannelReady(node); i++, requests++) {
selector.send(new NetworkSend(node, ByteBuffer.wrap((prefix + "-" + requests).getBytes())));
}
}
}
示例2: shouldAcceptValidTopicNames
import org.apache.kafka.test.TestUtils; //导入方法依赖的package包/类
@Test
public void shouldAcceptValidTopicNames() {
String maxLengthString = TestUtils.randomString(249);
String[] validTopicNames = {"valid", "TOPIC", "nAmEs", "ar6", "VaL1d", "_0-9_.", "...", maxLengthString};
for (String topicName : validTopicNames) {
Topic.validate(topicName);
}
}
示例3: testNetworkThreadTimeRecorded
import org.apache.kafka.test.TestUtils; //导入方法依赖的package包/类
/**
* Tests that time spent on the network thread is accumulated on each channel
*/
@Test
public void testNetworkThreadTimeRecorded() throws Exception {
selector.close();
this.selector = new Selector(NetworkReceive.UNLIMITED, 5000, new Metrics(), Time.SYSTEM,
"MetricGroup", new HashMap<String, String>(), false, true, channelBuilder);
String node = "0";
server = createEchoServer(SecurityProtocol.SSL);
InetSocketAddress addr = new InetSocketAddress("localhost", server.port());
selector.connect(node, addr, BUFFER_SIZE, BUFFER_SIZE);
String message = TestUtils.randomString(10 * 1024);
NetworkTestUtils.waitForChannelReady(selector, node);
KafkaChannel channel = selector.channel(node);
assertTrue("SSL handshake time not recorded", channel.getAndResetNetworkThreadTimeNanos() > 0);
assertEquals("Time not reset", 0, channel.getAndResetNetworkThreadTimeNanos());
selector.mute(node);
selector.send(new NetworkSend(node, ByteBuffer.wrap(message.getBytes())));
while (selector.completedSends().isEmpty()) {
selector.poll(100L);
}
assertTrue("Send time not recorded", channel.getAndResetNetworkThreadTimeNanos() > 0);
assertEquals("Time not reset", 0, channel.getAndResetNetworkThreadTimeNanos());
selector.unmute(node);
while (selector.completedReceives().isEmpty()) {
selector.poll(100L);
}
assertTrue("Receive time not recorded", channel.getAndResetNetworkThreadTimeNanos() > 0);
}
示例4: testSendLargeRequest
import org.apache.kafka.test.TestUtils; //导入方法依赖的package包/类
/**
* Validate that we can send and receive a message larger than the receive and send buffer size
*/
@Test
public void testSendLargeRequest() throws Exception {
String node = "0";
blockingConnect(node);
String big = TestUtils.randomString(10 * BUFFER_SIZE);
assertEquals(big, blockingRequest(node, big));
}
示例5: testLargeMessageSequence
import org.apache.kafka.test.TestUtils; //导入方法依赖的package包/类
@Test
public void testLargeMessageSequence() throws Exception {
int bufferSize = 512 * 1024;
String node = "0";
int reqs = 50;
InetSocketAddress addr = new InetSocketAddress("localhost", server.port);
connect(node, addr);
String requestPrefix = TestUtils.randomString(bufferSize);
sendAndReceive(node, requestPrefix, 0, reqs);
}
示例6: before
import org.apache.kafka.test.TestUtils; //导入方法依赖的package包/类
@Before
public void before() {
stateDir = new File(TestUtils.IO_TMP_DIR, TestUtils.randomString(5));
directory = new StateDirectory(applicationId, stateDir.getPath(), time);
appDir = new File(stateDir, applicationId);
}