Skip to content

Commit c06d73f

Browse files
committed
add stress tests
1 parent 8ac37e3 commit c06d73f

File tree

2 files changed

+140
-0
lines changed

2 files changed

+140
-0
lines changed
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
package de.rwth.idsg.steve;
2+
3+
import de.rwth.idsg.steve.utils.StressTester;
4+
import de.rwth.idsg.steve.utils.__DatabasePreparer__;
5+
import lombok.extern.slf4j.Slf4j;
6+
import ocpp.cs._2015._10.AuthorizationStatus;
7+
import ocpp.cs._2015._10.AuthorizeRequest;
8+
import ocpp.cs._2015._10.AuthorizeResponse;
9+
import ocpp.cs._2015._10.BootNotificationRequest;
10+
import ocpp.cs._2015._10.BootNotificationResponse;
11+
import ocpp.cs._2015._10.CentralSystemService;
12+
import ocpp.cs._2015._10.RegistrationStatus;
13+
import org.junit.After;
14+
import org.junit.AfterClass;
15+
import org.junit.Assert;
16+
import org.junit.Before;
17+
import org.junit.BeforeClass;
18+
import org.junit.Test;
19+
20+
import static de.rwth.idsg.steve.utils.Helpers.getForOcpp16;
21+
import static de.rwth.idsg.steve.utils.Helpers.getPath;
22+
import static de.rwth.idsg.steve.utils.Helpers.getRandomString;
23+
24+
/**
25+
* @author Sevket Goekay <goekay@dbis.rwth-aachen.de>
26+
* @since 18.04.2018
27+
*/
28+
@Slf4j
29+
public class StressTestSoapOCPP16 {
30+
31+
private static final String REGISTERED_CHARGE_BOX_ID = __DatabasePreparer__.getRegisteredChargeBoxId();
32+
33+
private static final String path = getPath();
34+
private static Application app;
35+
36+
@BeforeClass
37+
public static void initClass() throws Exception {
38+
Assert.assertEquals(ApplicationProfile.TEST, SteveConfiguration.CONFIG.getProfile());
39+
Assert.assertTrue(SteveConfiguration.CONFIG.getOcpp().isAutoRegisterUnknownStations());
40+
41+
app = new Application();
42+
app.start();
43+
}
44+
45+
@AfterClass
46+
public static void destroyClass() throws Exception {
47+
if (app != null) {
48+
app.stop();
49+
}
50+
}
51+
52+
@Before
53+
public void init() {
54+
__DatabasePreparer__.prepare();
55+
}
56+
57+
@After
58+
public void destroy() {
59+
__DatabasePreparer__.cleanUp();
60+
}
61+
62+
@Test
63+
public void testBootNotification() throws Exception {
64+
StressTester tester = new StressTester(50, 5);
65+
66+
CentralSystemService client = getForOcpp16(path);
67+
68+
tester.test(() -> {
69+
BootNotificationResponse boot = client.bootNotification(
70+
new BootNotificationRequest()
71+
.withChargePointVendor(getRandomString())
72+
.withChargePointModel(getRandomString()),
73+
getRandomString());
74+
Assert.assertEquals(RegistrationStatus.ACCEPTED, boot.getStatus());
75+
});
76+
77+
tester.shutDown();
78+
}
79+
80+
@Test
81+
public void testAuthorize() throws Exception {
82+
StressTester tester = new StressTester(100, 10);
83+
84+
CentralSystemService client = getForOcpp16(path);
85+
86+
tester.test(() -> {
87+
AuthorizeResponse auth = client.authorize(
88+
new AuthorizeRequest().withIdTag(getRandomString()),
89+
REGISTERED_CHARGE_BOX_ID);
90+
Assert.assertEquals(AuthorizationStatus.INVALID, auth.getIdTagInfo().getStatus());
91+
});
92+
93+
tester.shutDown();
94+
}
95+
96+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
package de.rwth.idsg.steve.utils;
2+
3+
import java.util.concurrent.CountDownLatch;
4+
import java.util.concurrent.ExecutorService;
5+
import java.util.concurrent.Executors;
6+
7+
/**
8+
* @author Sevket Goekay <goekay@dbis.rwth-aachen.de>
9+
* @since 18.04.2018
10+
*/
11+
public class StressTester {
12+
13+
private final int threadCount;
14+
private final int perThreadRepeatCount;
15+
private final ExecutorService executorService;
16+
17+
public StressTester(int threadCount, int perThreadRepeatCount) {
18+
this.threadCount = threadCount;
19+
this.perThreadRepeatCount = perThreadRepeatCount;
20+
this.executorService = Executors.newCachedThreadPool();
21+
}
22+
23+
public void test(Runnable action) throws InterruptedException {
24+
final CountDownLatch doneSignal = new CountDownLatch(threadCount);
25+
26+
for (int i = 0; i < threadCount; i++) {
27+
executorService.execute(() -> {
28+
try {
29+
for (int j = 0; j < perThreadRepeatCount; j++) {
30+
action.run();
31+
}
32+
} finally {
33+
doneSignal.countDown();
34+
}
35+
});
36+
}
37+
38+
doneSignal.await();
39+
}
40+
41+
public void shutDown() {
42+
executorService.shutdown();
43+
}
44+
}

0 commit comments

Comments
 (0)