use of jodd.mutable.MutableInteger in project jodd by oblac.
the class FuturesTest method testFailAfterOnManyTasks.
@Test
public void testFailAfterOnManyTasks() throws ExecutionException, InterruptedException {
MutableInteger execCount = new MutableInteger();
MutableInteger interruptCount = new MutableInteger();
final CompletableFuture<String> asyncCode1 = CompletableFuture.supplyAsync(() -> {
ThreadUtil.sleep(1000);
execCount.value++;
return "done";
});
final CompletableFuture<String> asyncCode2 = CompletableFuture.supplyAsync(() -> {
ThreadUtil.sleep(2000);
execCount.value++;
return "done";
});
final CompletableFuture<String> asyncCode3 = CompletableFuture.supplyAsync(() -> {
ThreadUtil.sleep(3000);
execCount.value++;
return "done";
});
CompletableFuture<String> f1 = Futures.within(asyncCode1, Duration.ofMillis(1500)).exceptionally(throwable -> {
interruptCount.value++;
return null;
});
CompletableFuture<String> f2 = Futures.within(asyncCode2, Duration.ofMillis(1500)).exceptionally(throwable -> {
interruptCount.value++;
return null;
});
CompletableFuture<String> f3 = Futures.within(asyncCode3, Duration.ofMillis(1500)).exceptionally(throwable -> {
interruptCount.value++;
return null;
});
CompletableFuture.allOf(f1, f2, f3).get();
assertEquals(1, execCount.value);
assertEquals(2, interruptCount.value);
}
use of jodd.mutable.MutableInteger in project jodd by oblac.
the class LFUCacheTest method testOnRemove.
@Test
public void testOnRemove() {
final MutableInteger mutableInteger = new MutableInteger();
Cache<String, String> cache = new LFUCache<String, String>(2) {
@Override
protected void onRemove(String key, String cachedObject) {
mutableInteger.value++;
}
};
cache.put("1", "val1");
cache.put("2", "val2");
assertEquals(0, mutableInteger.value);
cache.put("3", "val3");
assertEquals(2, mutableInteger.value);
}
use of jodd.mutable.MutableInteger in project jodd by oblac.
the class FindFileTest method testTwoAccept.
@Test
public void testTwoAccept() {
FindFile ff = new WildcardFindFile().include("**/*file/a.png").include("**/*file/a.txt").setRecursive(true).setIncludeDirs(true).searchPath(dataRoot);
final MutableInteger countFiles = new MutableInteger();
final MutableInteger countDirs = new MutableInteger();
ff.find(new FileConsumer() {
@Override
public boolean onFile(File f) {
if (f.isDirectory()) {
countDirs.value++;
} else {
countFiles.value++;
String path = f.getAbsolutePath();
path = FileNameUtil.separatorsToUnix(path);
if (!path.startsWith("/")) {
path = '/' + path;
}
boolean matched = path.equals(dataRoot + "/file/a.png") || path.equals(dataRoot + "/file/a.txt");
assertTrue(matched);
}
return true;
}
});
assertEquals(0, countDirs.value);
assertEquals(2, countFiles.value);
}
use of jodd.mutable.MutableInteger in project jodd by oblac.
the class FormProcessorVisitor method valueToString.
/**
* Converts value to a string.
*/
protected String valueToString(String name, Object valueObject) {
if (!valueObject.getClass().isArray()) {
return valueObject.toString();
}
// array
String[] array = (String[]) valueObject;
if (valueNameIndexes == null) {
valueNameIndexes = new HashMap<>();
}
MutableInteger index = valueNameIndexes.get(name);
if (index == null) {
index = new MutableInteger(0);
valueNameIndexes.put(name, index);
}
if (index.value >= array.length) {
return null;
}
String result = array[index.value];
index.value++;
return result;
}
use of jodd.mutable.MutableInteger in project jodd by oblac.
the class ObjectUtilTest method testCloneViaSerialization.
@Test
public void testCloneViaSerialization() throws Exception {
MutableInteger mu = new MutableInteger(183);
MutableInteger mu2 = ObjectUtil.cloneViaSerialization(mu);
assertFalse(mu == mu2);
assertTrue(mu.equals(mu2));
assertEquals(mu.intValue(), mu2.intValue());
}
Aggregations