mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-11-30 01:34:04 +00:00
Iris binds AtomicCache's failure handler to its logging and error reporting at startup
This commit is contained in:
1 parent
80d50b5cff
commit
9d886e3c69
11 files changed
+56
-944
No files matched your search
@@ -33,7 +33,7 @@ public class DiagnosticSeverityPolicyTest {
|
||||
assertLoggedWith("engine/mantle/MantleWriter.java", "Mantle Writer Accessed chunk out of bounds", "debug");
|
||||
assertLoggedWith("engine/decorator/ResolvedDecorator.java", "Empty Block Data for ", "warnOnce");
|
||||
assertLoggedWith("engine/object/compatibility/IrisCompat.java", "Can't find block data for ", "warnOnce");
|
||||
assertLoggedWith("engine/data/cache/AtomicCache.java", "Atomic cache supplier failed: %s: %s", "warnOnce");
|
||||
assertLoggedWith("engine/data/cache/AtomicCacheFailureReporting.java", "Atomic cache supplier failed: %s: %s", "warnOnce");
|
||||
assertLoggedWith("engine/IrisComplex.java", "Failed to sample interpolated biome bounds", "warnOnce");
|
||||
assertLoggedWith("engine/framework/placer/WorldObjectPlacer.java", "Tried to place custom block at", "warnOnce");
|
||||
}
|
||||
|
||||
@@ -1,106 +0,0 @@
|
||||
package art.arcane.iris.engine.data.cache;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertSame;
|
||||
import static org.junit.Assert.assertThrows;
|
||||
|
||||
public class AtomicCacheTest {
|
||||
@Test
|
||||
public void aquireOnceOrThrowCachesTheComputedValue() {
|
||||
AtomicCache<String> cache = new AtomicCache<>();
|
||||
AtomicInteger calls = new AtomicInteger();
|
||||
|
||||
assertEquals("value", cache.aquireOnceOrThrow(() -> {
|
||||
calls.incrementAndGet();
|
||||
return "value";
|
||||
}));
|
||||
assertEquals("value", cache.aquireOnceOrThrow(() -> {
|
||||
calls.incrementAndGet();
|
||||
return "other";
|
||||
}));
|
||||
assertEquals(1, calls.get());
|
||||
}
|
||||
|
||||
/**
|
||||
* The retrying variant is what a caller that can repair the cause between attempts needs, and the
|
||||
* world generator relies on it, so memoization must stay confined to aquireOnceOrThrow.
|
||||
*/
|
||||
@Test
|
||||
public void aquireOrThrowStillRetriesAFailedSupplier() {
|
||||
AtomicCache<String> cache = new AtomicCache<>();
|
||||
AtomicInteger calls = new AtomicInteger();
|
||||
|
||||
assertThrows(IllegalStateException.class, () -> cache.aquireOrThrow(() -> {
|
||||
calls.incrementAndGet();
|
||||
throw new IllegalStateException("repairable");
|
||||
}));
|
||||
assertEquals("repaired", cache.aquireOrThrow(() -> {
|
||||
calls.incrementAndGet();
|
||||
return "repaired";
|
||||
}));
|
||||
assertEquals(2, calls.get());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void aquireOnceOrThrowMemoizesTheSupplierFailureInsteadOfRerunningIt() {
|
||||
AtomicCache<String> cache = new AtomicCache<>();
|
||||
AtomicInteger calls = new AtomicInteger();
|
||||
IllegalStateException cause = new IllegalStateException("Frozen Iris pack snapshot is missing");
|
||||
|
||||
IllegalStateException first = assertThrows(IllegalStateException.class, () -> cache.aquireOnceOrThrow(() -> {
|
||||
calls.incrementAndGet();
|
||||
throw cause;
|
||||
}));
|
||||
IllegalStateException second = assertThrows(IllegalStateException.class, () -> cache.aquireOnceOrThrow(() -> {
|
||||
calls.incrementAndGet();
|
||||
return "recovered";
|
||||
}));
|
||||
|
||||
assertSame(cause, first);
|
||||
assertSame(cause, second);
|
||||
assertEquals("the failure is stated once and replayed, never recomputed", 1, calls.get());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void aquireOnceOrThrowRejectsANullValueAndRemembersThat() {
|
||||
AtomicCache<String> cache = new AtomicCache<>();
|
||||
AtomicInteger calls = new AtomicInteger();
|
||||
|
||||
assertThrows(IllegalStateException.class, () -> cache.aquireOnceOrThrow(() -> {
|
||||
calls.incrementAndGet();
|
||||
return null;
|
||||
}));
|
||||
assertThrows(IllegalStateException.class, () -> cache.aquireOnceOrThrow(() -> {
|
||||
calls.incrementAndGet();
|
||||
return "recovered";
|
||||
}));
|
||||
assertEquals(1, calls.get());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void resetClearsAMemoizedFailure() {
|
||||
AtomicCache<String> cache = new AtomicCache<>();
|
||||
|
||||
assertThrows(IllegalStateException.class, () -> cache.aquireOnceOrThrow(() -> {
|
||||
throw new IllegalStateException("transient");
|
||||
}));
|
||||
cache.reset();
|
||||
|
||||
assertEquals("recovered", cache.aquireOnceOrThrow(() -> "recovered"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void aquireStillSwallowsFailuresForOptionalValues() {
|
||||
AtomicCache<String> cache = new AtomicCache<>();
|
||||
|
||||
assertNull(cache.aquire(() -> {
|
||||
throw new IllegalStateException("optional value");
|
||||
}));
|
||||
assertEquals("later", cache.aquire(() -> "later"));
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user