@@ -68,30 +68,33 @@ public static void main(String[] args) throws Exception {
6868
6969 final Random rand = new Random (1L );
7070
71- long sizeLeak1 , sizeLeak2 , sizeLeak3 ;
71+ long sizeLeak1 = -1 ;
72+ long sizeLeak2 = -1 ;
73+ long sizeLeak3 = -1 ;
7274
7375 do {
74- sizeLeak1 = -1 ;
75- sizeLeak2 = -1 ;
76- sizeLeak3 = -1 ;
77-
7876 try (Recording recording = new Recording ()) {
7977 leak .clear ();
8078 recording .enable (EventNames .OldObjectSample ).withStackTrace ().with ("cutoff" , "infinity" );
8179 recording .start ();
8280
8381 for (int i = 0 ; i < 1000 ; i ++) {
84- switch (rand .nextInt (3 )) {
85- case 0 : leak .add (new Leak1 ()); break ;
86- case 1 : leak .add (new Leak2 ()); break ;
87- case 2 : leak .add (new Leak3 ()); break ;
82+ if (sizeLeak1 == -1 ) {
83+ leak .add (new Leak1 ());
84+ continue ;
85+ }
86+ if (sizeLeak2 == -1 ) {
87+ leak .add (new Leak2 ());
88+ continue ;
89+ }
90+ if (sizeLeak3 == -1 ) {
91+ leak .add (new Leak3 ());
8892 }
8993 }
9094
9195 recording .stop ();
9296
9397 List <RecordedEvent > events = Events .fromRecording (recording );
94- Events .hasEvents (events );
9598 for (RecordedEvent e : events ) {
9699 RecordedObject object = e .getValue ("object" );
97100 RecordedClass type = object .getValue ("type" );
@@ -100,13 +103,13 @@ public static void main(String[] args) throws Exception {
100103 if (objectSize <= 0 ) {
101104 throw new Exception ("Object size for " + type .getName () + " is lower or equal to 0" );
102105 }
103- if (type .getName ().equals (Leak1 .class .getName ())) {
106+ if (type .getName ().equals (Leak1 .class .getName ()) && sizeLeak1 == - 1 ) {
104107 sizeLeak1 = objectSize ;
105108 }
106- if (type .getName ().equals (Leak2 .class .getName ())) {
109+ if (type .getName ().equals (Leak2 .class .getName ()) && sizeLeak2 == - 1 ) {
107110 sizeLeak2 = objectSize ;
108111 }
109- if (type .getName ().equals (Leak3 .class .getName ())) {
112+ if (type .getName ().equals (Leak3 .class .getName ()) && sizeLeak3 == - 1 ) {
110113 sizeLeak3 = objectSize ;
111114 }
112115 }
0 commit comments