Skip to content

Commit 0080681

Browse files
author
Frohwalt Egerer
committed
Run some tests repeatedly, they seem not to be stable
1 parent 55c7725 commit 0080681

File tree

5 files changed

+67
-8
lines changed

5 files changed

+67
-8
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<modelVersion>4.0.0</modelVersion>
44
<groupId>com.notnoop.apns</groupId>
55
<artifactId>apns</artifactId>
6-
<version>0.2.4-SNAPSHOT</version>
6+
<version>1.0.0-SNAPSHOT</version>
77
<packaging>jar</packaging>
88
<name>Java Apple Push Notification Service Library</name>
99

src/test/java/com/notnoop/apns/integration/ApnsConnectionTest.java

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,22 @@
55
import com.notnoop.apns.EnhancedApnsNotification;
66
import com.notnoop.apns.SimpleApnsNotification;
77
import com.notnoop.apns.utils.ApnsServerStub;
8+
import com.notnoop.apns.utils.junit.Repeat;
9+
import com.notnoop.apns.utils.junit.RepeatRule;
810
import org.junit.After;
911
import org.junit.Before;
12+
import org.junit.Rule;
1013
import org.junit.Test;
1114
import static com.notnoop.apns.utils.FixedCertificates.*;
1215
import static org.junit.Assert.*;
1316

17+
1418
@SuppressWarnings("ALL")
1519
public class ApnsConnectionTest {
1620

21+
@Rule
22+
public RepeatRule rr = new RepeatRule();
23+
1724
ApnsServerStub server;
1825
static SimpleApnsNotification msg1 = new SimpleApnsNotification("a87d8878d878a79", "{\"aps\":{}}");
1926
static SimpleApnsNotification msg2 = new SimpleApnsNotification("a87d8878d878a88", "{\"aps\":{}}");
@@ -37,9 +44,9 @@ public void tearDown() {
3744
server = null;
3845
}
3946

47+
@Repeat(count = 50)
4048
@Test(timeout = 2000)
4149
public void sendOneSimple() throws InterruptedException {
42-
4350
ApnsService service =
4451
APNS.newService().withSSLContext(clientContext())
4552
.withGatewayDestination(LOCALHOST, gatewayPort)
@@ -51,10 +58,9 @@ public void sendOneSimple() throws InterruptedException {
5158
assertArrayEquals(msg1.marshall(), server.getReceived().toByteArray());
5259
}
5360

61+
@Repeat(count = 50)
5462
@Test(timeout = 2000)
5563
public void sendOneQueued() throws InterruptedException {
56-
57-
5864
ApnsService service =
5965
APNS.newService().withSSLContext(clientContext())
6066
.withGatewayDestination(LOCALHOST, gatewayPort)
@@ -66,8 +72,8 @@ public void sendOneQueued() throws InterruptedException {
6672

6773
assertArrayEquals(msg1.marshall(), server.getReceived().toByteArray());
6874
}
69-
70-
75+
76+
7177
@Test
7278
public void sendOneSimpleWithoutTimeout() throws InterruptedException {
7379
server.getToWaitBeforeSend().set(2000);

src/test/java/com/notnoop/apns/utils/ApnsServerStub.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import java.io.OutputStream;
77
import java.net.ServerSocket;
88
import java.net.Socket;
9+
import java.net.SocketException;
910
import java.nio.ByteBuffer;
1011
import java.util.concurrent.Semaphore;
1112
import java.util.concurrent.atomic.AtomicInteger;
@@ -114,7 +115,10 @@ public void sendError(int err, int id) {
114115
gatewayOutLock.acquire();
115116
gatewayOutputStream.write(buf.array());
116117
gatewayOutputStream.flush();
117-
} catch (Exception ex) {
118+
}
119+
120+
121+
catch (Exception ex) {
118122
ex.printStackTrace();
119123
}
120124
}
@@ -236,8 +240,10 @@ public void run() {
236240
// Close the socket
237241
in.close();
238242
out.close();
243+
} catch (SocketException se) {
244+
// Ignore closed socket.
239245
} catch (IOException ioex) {
240-
System.err.println(ioex.toString());
246+
ioex.printStackTrace();
241247
}
242248
messages.release();
243249
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package com.notnoop.apns.utils.junit;
2+
3+
import java.lang.annotation.Retention;
4+
import java.lang.annotation.RetentionPolicy;
5+
import java.lang.annotation.Target;
6+
7+
@Retention(RetentionPolicy.RUNTIME)
8+
@Target({java.lang.annotation.ElementType.METHOD})
9+
public @interface Repeat {
10+
public abstract int count();
11+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package com.notnoop.apns.utils.junit;
2+
3+
4+
import org.junit.rules.TestRule;
5+
import org.junit.runner.Description;
6+
import org.junit.runners.model.Statement;
7+
8+
public class RepeatRule implements TestRule {
9+
10+
@Override
11+
public Statement apply(Statement base, Description description) {
12+
Repeat repeat = description.getAnnotation(Repeat.class);
13+
if (repeat != null) {
14+
return new RepeatStatement(repeat.count(), base);
15+
}
16+
return base;
17+
}
18+
19+
private static class RepeatStatement extends Statement {
20+
21+
private final int count;
22+
private final Statement base;
23+
24+
private RepeatStatement(int count, Statement base) {
25+
this.count = count;
26+
this.base = base;
27+
}
28+
29+
@Override
30+
public void evaluate() throws Throwable {
31+
for (int i = count; i > 0; i--) {
32+
base.evaluate();
33+
}
34+
}
35+
}
36+
}

0 commit comments

Comments
 (0)