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