22
33import com .arcadedb .test .support .ContainersTestTemplate ;
44import com .arcadedb .test .support .DatabaseWrapper ;
5+ import io .micrometer .core .instrument .Metrics ;
56import org .junit .jupiter .api .DisplayName ;
67import org .junit .jupiter .api .Test ;
78import org .testcontainers .containers .GenericContainer ;
89
910import java .io .IOException ;
11+ import java .time .Duration ;
12+ import java .time .LocalDateTime ;
13+ import java .time .format .DateTimeFormatter ;
1014import java .util .concurrent .ExecutorService ;
1115import java .util .concurrent .Executors ;
1216import java .util .concurrent .TimeUnit ;
@@ -18,58 +22,91 @@ public class SingleServerLoadTestIT extends ContainersTestTemplate {
1822 void singleServerLoadTest () throws InterruptedException , IOException {
1923
2024 GenericContainer <?> arcadeContainer = createArcadeContainer ("arcade" , "none" , "none" , "any" , false , network );
21-
2225 startContainers ();
23-
24- DatabaseWrapper db = new DatabaseWrapper (arcadeContainer , idSupplier );
26+ String host = arcadeContainer .getHost ();
27+ int port = arcadeContainer .getMappedPort (2480 );
28+ DatabaseWrapper db = new DatabaseWrapper (host , port , idSupplier );
2529 db .createDatabase ();
2630 db .createSchema ();
2731
28- final int numOfThreads = 5 ;
29- final int numOfUsers = 1000 ;
30- final int numOfPhotos = 10 ;
31- final int numOfFriendship = 1000 ;
32+ // Parameters for the test
33+ final int numOfThreads = 5 ; //number of threads to use to insert users and photos
34+ final int numOfUsers = 10000 ; // Each thread will create 200000 users
35+ final int numOfPhotos = 10 ; // Each user will have 5 photos
36+ final int numOfFriendship = 1000 ; // Each thread will create 100000 friendships
37+ final int numOfLike = 1000 ; // Each thread will create 100000 likes
3238
3339 int expectedUsersCount = numOfUsers * numOfThreads ;
34- int expectedFriendshipCount = numOfFriendship * numOfThreads ;
3540 int expectedPhotoCount = expectedUsersCount * numOfPhotos ;
36-
41+ int expectedFriendshipCount = numOfFriendship ;
42+ int expectedLikeCount = numOfLike ;
43+ LocalDateTime startedAt = LocalDateTime .now ();
3744 logger .info ("Creating {} users using {} threads" , expectedUsersCount , numOfThreads );
38- ExecutorService executor = Executors .newFixedThreadPool (numOfThreads );
45+ logger .info ("Expected users: {} - photos: {} - friendships: {} - likes: {}" , expectedUsersCount , expectedPhotoCount ,
46+ expectedFriendshipCount , expectedLikeCount );
47+ logger .info ("Starting at {}" , DateTimeFormatter .ISO_LOCAL_DATE_TIME .format (startedAt ));
48+
49+ ExecutorService executor = Executors .newFixedThreadPool (10 );
3950 for (int i = 0 ; i < numOfThreads ; i ++) {
4051 // Each thread will create users and photos
4152 executor .submit (() -> {
42- DatabaseWrapper db1 = new DatabaseWrapper (arcadeContainer , idSupplier );
53+ DatabaseWrapper db1 = new DatabaseWrapper (host , port , idSupplier );
4354 db1 .addUserAndPhotos (numOfUsers , numOfPhotos );
4455 db1 .close ();
4556 });
57+ }
4658
47- TimeUnit . SECONDS . sleep ( 2 );
59+ if ( numOfFriendship > 0 ) {
4860 // Each thread will create friendships
4961 executor .submit (() -> {
50- DatabaseWrapper db1 = new DatabaseWrapper (arcadeContainer , idSupplier );
62+ DatabaseWrapper db1 = new DatabaseWrapper (host , port , idSupplier );
5163 db1 .createFriendships (numOfFriendship );
5264 db1 .close ();
5365 });
5466 }
5567
68+ if (numOfLike > 0 ) {
69+ // Each thread will create friendships
70+ executor .submit (() -> {
71+ DatabaseWrapper db1 = new DatabaseWrapper (host , port , idSupplier );
72+ ;
73+ db1 .createLike (numOfLike );
74+ db1 .close ();
75+ });
76+ }
77+
5678 executor .shutdown ();
79+
5780 while (!executor .isTerminated ()) {
58- long users = db .countUsers ();
59- long friendships = db .countFriendships ();
60- long photos = db .countPhotos ();
61- logger .info ("Current users: {} - photos: {} - friendships: {}" , users , photos , friendships );
62- // Wait for 2 seconds before checking again
6381 try {
82+ long users = db .countUsers ();
83+ long friendships = db .countFriendships ();
84+ long photos = db .countPhotos ();
85+ long likes = db .countLikes ();
86+ logger .info ("Current users: {} - photos: {} - friendships: {} - likes: {}" , users , photos , friendships , likes );
87+ } catch (Exception e ) {
88+ logger .error (e .getMessage (), e );
89+ }
90+ try {
91+ // Wait for 2 seconds before checking again
6492 TimeUnit .SECONDS .sleep (2 );
6593 } catch (InterruptedException e ) {
6694 Thread .currentThread ().interrupt ();
6795 }
6896 }
6997
98+ LocalDateTime finishedAt = LocalDateTime .now ();
99+ logger .info ("Finishing at {}" , DateTimeFormatter .ISO_LOCAL_DATE_TIME .format (finishedAt ));
100+ logger .info ("Total time: {} minutes" , Duration .between (startedAt , finishedAt ).toMinutes ());
101+
102+ Metrics .globalRegistry .getMeters ().forEach (meter -> {
103+ logger .info ("Meter: {} - {}" , meter .getId ().getName (), meter .measure ());
104+ });
105+
70106 db .assertThatUserCountIs (expectedUsersCount );
71107 db .assertThatPhotoCountIs (expectedPhotoCount );
72108 db .assertThatFriendshipCountIs (expectedFriendshipCount );
109+ db .assertThatLikesCountIs (expectedLikeCount );
73110
74111 }
75112
0 commit comments