Skip to content

Commit a364980

Browse files
committed
Revert "make world size calculate async"
This reverts commit d1e626e.
1 parent d1e626e commit a364980

File tree

2 files changed

+8
-16
lines changed

2 files changed

+8
-16
lines changed

src/main/java/de/sldk/mc/metrics/WorldSize.java

+6-12
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22

33
import de.sldk.mc.utils.PathFileSize;
44
import io.prometheus.client.Gauge;
5-
6-
import java.util.concurrent.CompletableFuture;
75
import java.util.logging.Logger;
86
import org.bukkit.World;
97
import org.bukkit.plugin.Plugin;
@@ -29,17 +27,13 @@ protected void clear() {
2927

3028
@Override
3129
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();
4133
String worldName = world.getName();
4234
WORLD_SIZE.labels(worldName).set(size);
43-
});
35+
} catch (Throwable t) {
36+
log.throwing(this.getClass().getSimpleName(), "collect", t);
37+
}
4438
}
4539
}

src/test/java/de/sldk/mc/metrics/WorldSizeTest.java

+2-4
Original file line numberDiff line numberDiff line change
@@ -50,21 +50,19 @@ public void doesNotPopulateMetricIfFileDoesNotExist() {
5050
}
5151

5252
@Test
53-
public void setsMetricWithCorrectNameAndLabel() throws InterruptedException {
53+
public void setsMetricWithCorrectNameAndLabel() {
5454
String worldName = new RandomString(10).nextString();
5555
givenWorldFileExists(worldName);
5656
worldSizeMetric.collect(world);
57-
Thread.sleep(500);
5857
assertNotNull(getMetricValue(worldName));
5958
}
6059

6160
@Test
62-
public void setsCorrectWorldSizeValue() throws IOException, InterruptedException {
61+
public void setsCorrectWorldSizeValue() throws IOException {
6362
String worldName = new RandomString(10).nextString();
6463
int worldSize = new Random().ints(128, 1024).findFirst().getAsInt();
6564
givenWorldFileExists(worldName, worldSize);
6665
worldSizeMetric.collect(world);
67-
Thread.sleep(500);
6866
Double value = getMetricValue(worldName);
6967
assertEquals(worldSize, value.longValue());
7068
}

0 commit comments

Comments
 (0)