File tree 2 files changed +16
-8
lines changed
main/java/de/sldk/mc/metrics
test/java/de/sldk/mc/metrics
2 files changed +16
-8
lines changed Original file line number Diff line number Diff line change 2
2
3
3
import de .sldk .mc .utils .PathFileSize ;
4
4
import io .prometheus .client .Gauge ;
5
+
6
+ import java .util .concurrent .CompletableFuture ;
5
7
import java .util .logging .Logger ;
6
8
import org .bukkit .World ;
7
9
import org .bukkit .plugin .Plugin ;
@@ -27,13 +29,17 @@ protected void clear() {
27
29
28
30
@ Override
29
31
public void collect (World world ) {
30
- try {
31
- PathFileSize pathUtils = new PathFileSize (world .getWorldFolder ().toPath ());
32
- long size = pathUtils .getSize ();
32
+ CompletableFuture .supplyAsync (() -> {
33
+ try {
34
+ PathFileSize pathUtils = new PathFileSize (world .getWorldFolder ().toPath ());
35
+ return pathUtils .getSize ();
36
+ } catch (Throwable t ) {
37
+ log .throwing (this .getClass ().getSimpleName (), "collect" , t );
38
+ }
39
+ return 0L ;
40
+ }).thenAccept (size -> {
33
41
String worldName = world .getName ();
34
42
WORLD_SIZE .labels (worldName ).set (size );
35
- } catch (Throwable t ) {
36
- log .throwing (this .getClass ().getSimpleName (), "collect" , t );
37
- }
43
+ });
38
44
}
39
45
}
Original file line number Diff line number Diff line change @@ -50,19 +50,21 @@ public void doesNotPopulateMetricIfFileDoesNotExist() {
50
50
}
51
51
52
52
@ Test
53
- public void setsMetricWithCorrectNameAndLabel () {
53
+ public void setsMetricWithCorrectNameAndLabel () throws InterruptedException {
54
54
String worldName = new RandomString (10 ).nextString ();
55
55
givenWorldFileExists (worldName );
56
56
worldSizeMetric .collect (world );
57
+ Thread .sleep (500 );
57
58
assertNotNull (getMetricValue (worldName ));
58
59
}
59
60
60
61
@ Test
61
- public void setsCorrectWorldSizeValue () throws IOException {
62
+ public void setsCorrectWorldSizeValue () throws IOException , InterruptedException {
62
63
String worldName = new RandomString (10 ).nextString ();
63
64
int worldSize = new Random ().ints (128 , 1024 ).findFirst ().getAsInt ();
64
65
givenWorldFileExists (worldName , worldSize );
65
66
worldSizeMetric .collect (world );
67
+ Thread .sleep (500 );
66
68
Double value = getMetricValue (worldName );
67
69
assertEquals (worldSize , value .longValue ());
68
70
}
You can’t perform that action at this time.
0 commit comments