Information about LockBasedStorageManager instances added to assertions

This commit is contained in:
Andrey Breslav
2014-02-03 06:43:20 +04:00
parent 950e8d521b
commit a90dbc48ef
2 changed files with 10 additions and 8 deletions
@@ -149,7 +149,7 @@ public class StorageManagerTest extends TestCase {
fail(); fail();
} }
catch (AssertionError e) { catch (AssertionError e) {
assertEquals("Recursion detected on input: !!!", e.getMessage()); assertTrue(e.getMessage().startsWith("Recursion detected on input: !!!"));
} }
} }
@@ -94,7 +94,7 @@ public class LockBasedStorageManager implements StorageManager {
@Override @Override
public String toString() { public String toString() {
return getClass().getSimpleName() + "@" + Integer.toHexString(hashCode()) + " (" + debugText + ')'; return getClass().getSimpleName() + "@" + Integer.toHexString(hashCode()) + " (" + debugText + ")";
} }
@NotNull @NotNull
@@ -213,7 +213,7 @@ public class LockBasedStorageManager implements StorageManager {
@NotNull @NotNull
protected <T> RecursionDetectedResult<T> recursionDetectedDefault() { protected <T> RecursionDetectedResult<T> recursionDetectedDefault() {
throw new IllegalStateException("Recursive call in a lazy value"); throw new IllegalStateException("Recursive call in a lazy value under " + this);
} }
private static class RecursionDetectedResult<T> { private static class RecursionDetectedResult<T> {
@@ -237,7 +237,7 @@ public class LockBasedStorageManager implements StorageManager {
} }
public T getValue() { public T getValue() {
assert !fallThrough : "A value requested from FALL_THROUGH "; assert !fallThrough : "A value requested from FALL_THROUGH in " + this;
return value; return value;
} }
@@ -365,7 +365,7 @@ public class LockBasedStorageManager implements StorageManager {
lock.lock(); lock.lock();
try { try {
value = cache.get(input); value = cache.get(input);
assert value != NotValue.COMPUTING : "Recursion detected on input: " + input; assert value != NotValue.COMPUTING : "Recursion detected on input: " + input + " under " + LockBasedStorageManager.this;
if (value != null) return WrappedValues.unescapeExceptionOrNull(value); if (value != null) return WrappedValues.unescapeExceptionOrNull(value);
AssertionError error = null; AssertionError error = null;
@@ -379,7 +379,8 @@ public class LockBasedStorageManager implements StorageManager {
// A seemingly obvious way to come about this case would be to declare a special exception class, but the problem is that // A seemingly obvious way to come about this case would be to declare a special exception class, but the problem is that
// one memoized function is likely to (indirectly) call another, and if this second one throws this exception, we are screwed // one memoized function is likely to (indirectly) call another, and if this second one throws this exception, we are screwed
if (oldValue != NotValue.COMPUTING) { if (oldValue != NotValue.COMPUTING) {
error = new AssertionError("Race condition detected on input " + input + ". Old value is " + oldValue); error = new AssertionError("Race condition detected on input " + input + ". Old value is " + oldValue +
" under " + LockBasedStorageManager.this);
throw error; throw error;
} }
@@ -389,7 +390,8 @@ public class LockBasedStorageManager implements StorageManager {
if (throwable == error) throw exceptionHandlingStrategy.handleException(throwable); if (throwable == error) throw exceptionHandlingStrategy.handleException(throwable);
Object oldValue = cache.put(input, WrappedValues.escapeThrowable(throwable)); Object oldValue = cache.put(input, WrappedValues.escapeThrowable(throwable));
assert oldValue == NotValue.COMPUTING : "Race condition detected on input " + input + ". Old value is " + oldValue; assert oldValue == NotValue.COMPUTING : "Race condition detected on input " + input + ". Old value is " + oldValue +
" under " + LockBasedStorageManager.this;
throw exceptionHandlingStrategy.handleException(throwable); throw exceptionHandlingStrategy.handleException(throwable);
} }
@@ -413,7 +415,7 @@ public class LockBasedStorageManager implements StorageManager {
@Override @Override
public V invoke(K input) { public V invoke(K input) {
V result = super.invoke(input); V result = super.invoke(input);
assert result != null : "compute() returned null"; assert result != null : "compute() returned null under " + LockBasedStorageManager.this;
return result; return result;
} }
} }