summaryrefslogtreecommitdiff
path: root/zookeeper-server/src/test/java/org/apache/zookeeper/test/MaxCnxnsTest.java
diff options
context:
space:
mode:
Diffstat (limited to 'zookeeper-server/src/test/java/org/apache/zookeeper/test/MaxCnxnsTest.java')
-rw-r--r--zookeeper-server/src/test/java/org/apache/zookeeper/test/MaxCnxnsTest.java38
1 files changed, 19 insertions, 19 deletions
diff --git a/zookeeper-server/src/test/java/org/apache/zookeeper/test/MaxCnxnsTest.java b/zookeeper-server/src/test/java/org/apache/zookeeper/test/MaxCnxnsTest.java
index a96e5a8e2..a927e3ef9 100644
--- a/zookeeper-server/src/test/java/org/apache/zookeeper/test/MaxCnxnsTest.java
+++ b/zookeeper-server/src/test/java/org/apache/zookeeper/test/MaxCnxnsTest.java
@@ -1,4 +1,4 @@
-/**
+/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
@@ -18,20 +18,20 @@
package org.apache.zookeeper.test;
+import static org.junit.Assert.assertSame;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.net.InetSocketAddress;
import java.nio.ByteBuffer;
import java.nio.channels.SocketChannel;
import java.util.concurrent.atomic.AtomicInteger;
-
import org.apache.jute.BinaryOutputArchive;
import org.apache.zookeeper.proto.ConnectRequest;
-import org.junit.Assert;
import org.junit.Test;
public class MaxCnxnsTest extends ClientBase {
- final private static int numCnxns = 30;
+
+ private static final int numCnxns = 30;
AtomicInteger numConnected = new AtomicInteger(0);
String host;
int port;
@@ -45,7 +45,7 @@ public class MaxCnxnsTest extends ClientBase {
class CnxnThread extends Thread {
public CnxnThread(int i) {
- super("CnxnThread-"+i);
+ super("CnxnThread-" + i);
}
public void run() {
@@ -58,10 +58,9 @@ public class MaxCnxnsTest extends ClientBase {
* this for loop.
*/
sChannel = SocketChannel.open();
- sChannel.connect(new InetSocketAddress(host,port));
+ sChannel.connect(new InetSocketAddress(host, port));
// Construct a connection request
- ConnectRequest conReq = new ConnectRequest(0, 0,
- 10000, 0, "password".getBytes());
+ ConnectRequest conReq = new ConnectRequest(0, 0, 10000, 0, "password".getBytes());
ByteArrayOutputStream baos = new ByteArrayOutputStream();
BinaryOutputArchive boa = BinaryOutputArchive.getArchive(baos);
boa.writeInt(-1, "len");
@@ -83,17 +82,16 @@ public class MaxCnxnsTest extends ClientBase {
*/
int eof = sChannel.write(bb);
- // If the socket times out, we count that as Assert.failed -
+ // If the socket times out, we count that as failed -
// the server should respond within 10s
sChannel.socket().setSoTimeout(10000);
- if (!sChannel.socket().isClosed()){
+ if (!sChannel.socket().isClosed()) {
eof = sChannel.socket().getInputStream().read();
if (eof != -1) {
numConnected.incrementAndGet();
}
}
- }
- catch (IOException io) {
+ } catch (IOException io) {
// "Connection reset by peer"
} finally {
if (sChannel != null) {
@@ -105,6 +103,7 @@ public class MaxCnxnsTest extends ClientBase {
}
}
}
+
}
/**
@@ -113,24 +112,25 @@ public class MaxCnxnsTest extends ClientBase {
* @throws InterruptedException
*/
@Test
- public void testMaxCnxns() throws IOException, InterruptedException{
- String split[] = hostPort.split(":");
+ public void testMaxCnxns() throws IOException, InterruptedException {
+ String[] split = hostPort.split(":");
host = split[0];
port = Integer.parseInt(split[1]);
int numThreads = numCnxns + 5;
CnxnThread[] threads = new CnxnThread[numThreads];
- for (int i=0;i<numCnxns;++i) {
- threads[i] = new CnxnThread(i);
+ for (int i = 0; i < numCnxns; ++i) {
+ threads[i] = new CnxnThread(i);
}
- for (int i=0;i<numCnxns;++i) {
+ for (int i = 0; i < numCnxns; ++i) {
threads[i].start();
}
- for (int i=0;i<numCnxns;++i) {
+ for (int i = 0; i < numCnxns; ++i) {
threads[i].join();
}
- Assert.assertSame(numCnxns,numConnected.get());
+ assertSame(numCnxns, numConnected.get());
}
+
}