diff --git a/src/main/java/org/dataloader/BatchLoader.java b/src/main/java/org/dataloader/BatchLoader.java index fed2baf..c1916e3 100644 --- a/src/main/java/org/dataloader/BatchLoader.java +++ b/src/main/java/org/dataloader/BatchLoader.java @@ -54,7 +54,7 @@ * The back-end service returned results in a different order than we requested, likely because it was more efficient for it to * do so. Also, it omitted a result for key 6, which we may interpret as no value existing for that key. *

- * To uphold the constraints of the batch function, it must return an List of values the same length as + * To uphold the constraints of the batch function, it must return a List of values the same length as * the List of keys, and re-order them to ensure each index aligns with the original keys [ 2, 9, 6, 1 ]: * *

diff --git a/src/main/java/org/dataloader/BatchLoaderEnvironment.java b/src/main/java/org/dataloader/BatchLoaderEnvironment.java
index dd2572b..6039a4a 100644
--- a/src/main/java/org/dataloader/BatchLoaderEnvironment.java
+++ b/src/main/java/org/dataloader/BatchLoaderEnvironment.java
@@ -54,7 +54,7 @@ public Map getKeyContexts() {
      * {@link org.dataloader.DataLoader#loadMany(java.util.List, java.util.List)} can be given
      * a context object when it is invoked.  A list of them is present by this method.
      *
-     * @return a list of key context objects in the order they where encountered
+     * @return a list of key context objects in the order they were encountered
      */
     public List getKeyContextsList() {
         return keyContextsList;
@@ -83,7 +83,7 @@ public  Builder keyContexts(List keys, List keyContexts) {
             Assertions.nonNull(keyContexts);
 
             Map map = new HashMap<>();
-            List list = new ArrayList<>();
+            List list = new ArrayList<>(keys.size());
             for (int i = 0; i < keys.size(); i++) {
                 K key = keys.get(i);
                 Object keyContext = null;
diff --git a/src/main/java/org/dataloader/CacheMap.java b/src/main/java/org/dataloader/CacheMap.java
index 6d27a47..48d0f41 100644
--- a/src/main/java/org/dataloader/CacheMap.java
+++ b/src/main/java/org/dataloader/CacheMap.java
@@ -65,7 +65,7 @@ static  CacheMap simpleMap() {
     /**
      * Gets the specified key from the cache map.
      * 

- * May throw an exception if the key does not exists, depending on the cache map implementation that is used, + * May throw an exception if the key does not exist, depending on the cache map implementation that is used, * so be sure to check {@link CacheMap#containsKey(Object)} first. * * @param key the key to retrieve diff --git a/src/main/java/org/dataloader/DataLoader.java b/src/main/java/org/dataloader/DataLoader.java index e800a55..1e4ce7d 100644 --- a/src/main/java/org/dataloader/DataLoader.java +++ b/src/main/java/org/dataloader/DataLoader.java @@ -108,7 +108,7 @@ public static DataLoader newDataLoader(BatchLoader batchLoadF * (batching, caching and unlimited batch size) where the batch loader function returns a list of * {@link org.dataloader.Try} objects. *

- * If its important you to know the exact status of each item in a batch call and whether it threw exceptions then + * If it's important you to know the exact status of each item in a batch call and whether it threw exceptions then * you can use this form to create the data loader. *

* Using Try objects allows you to capture a value returned or an exception that might @@ -186,7 +186,7 @@ public static DataLoader newDataLoader(BatchLoaderWithContext * (batching, caching and unlimited batch size) where the batch loader function returns a list of * {@link org.dataloader.Try} objects. *

- * If its important you to know the exact status of each item in a batch call and whether it threw exceptions then + * If it's important you to know the exact status of each item in a batch call and whether it threw exceptions then * you can use this form to create the data loader. *

* Using Try objects allows you to capture a value returned or an exception that might @@ -264,7 +264,7 @@ public static DataLoader newMappedDataLoader(MappedBatchLoader - * If its important you to know the exact status of each item in a batch call and whether it threw exceptions then + * If it's important you to know the exact status of each item in a batch call and whether it threw exceptions then * you can use this form to create the data loader. *

* Using Try objects allows you to capture a value returned or an exception that might @@ -343,7 +343,7 @@ public static DataLoader newMappedDataLoader(MappedBatchLoaderWithC * (batching, caching and unlimited batch size) where the batch loader function returns a list of * {@link org.dataloader.Try} objects. *

- * If its important you to know the exact status of each item in a batch call and whether it threw exceptions then + * If it's important you to know the exact status of each item in a batch call and whether it threw exceptions then * you can use this form to create the data loader. *

* Using Try objects allows you to capture a value returned or an exception that might @@ -471,11 +471,11 @@ public CompletableFuture load(K key) { * This will return an optional promise to a value previously loaded via a {@link #load(Object)} call or empty if not call has been made for that key. *

* If you do get a present CompletableFuture it does not mean it has been dispatched and completed yet. It just means - * its at least pending and in cache. + * it's at least pending and in cache. *

* If caching is disabled there will never be a present Optional returned. *

- * NOTE : This will NOT cause a data load to happen. You must called {@link #load(Object)} for that to happen. + * NOTE : This will NOT cause a data load to happen. You must call {@link #load(Object)} for that to happen. * * @param key the key to check * @@ -494,7 +494,7 @@ public Optional> getIfPresent(K key) { *

* If caching is disabled there will never be a present Optional returned. *

- * NOTE : This will NOT cause a data load to happen. You must called {@link #load(Object)} for that to happen. + * NOTE : This will NOT cause a data load to happen. You must call {@link #load(Object)} for that to happen. * * @param key the key to check * @@ -561,7 +561,7 @@ public CompletableFuture> loadMany(List keys, List keyContext nonNull(keyContexts); synchronized (this) { - List> collect = new ArrayList<>(); + List> collect = new ArrayList<>(keys.size()); for (int i = 0; i < keys.size(); i++) { K key = keys.get(i); Object keyContext = null; diff --git a/src/main/java/org/dataloader/DataLoaderFactory.java b/src/main/java/org/dataloader/DataLoaderFactory.java index 0f910c1..013f473 100644 --- a/src/main/java/org/dataloader/DataLoaderFactory.java +++ b/src/main/java/org/dataloader/DataLoaderFactory.java @@ -42,7 +42,7 @@ public static DataLoader newDataLoader(BatchLoader batchLoadF * (batching, caching and unlimited batch size) where the batch loader function returns a list of * {@link org.dataloader.Try} objects. *

- * If its important you to know the exact status of each item in a batch call and whether it threw exceptions then + * If it's important you to know the exact status of each item in a batch call and whether it threw exceptions then * you can use this form to create the data loader. *

* Using Try objects allows you to capture a value returned or an exception that might @@ -109,7 +109,7 @@ public static DataLoader newDataLoader(BatchLoaderWithContext * (batching, caching and unlimited batch size) where the batch loader function returns a list of * {@link org.dataloader.Try} objects. *

- * If its important you to know the exact status of each item in a batch call and whether it threw exceptions then + * If it's important you to know the exact status of each item in a batch call and whether it threw exceptions then * you can use this form to create the data loader. *

* Using Try objects allows you to capture a value returned or an exception that might @@ -176,7 +176,7 @@ public static DataLoader newMappedDataLoader(MappedBatchLoader - * If its important you to know the exact status of each item in a batch call and whether it threw exceptions then + * If it's important you to know the exact status of each item in a batch call and whether it threw exceptions then * you can use this form to create the data loader. *

* Using Try objects allows you to capture a value returned or an exception that might @@ -244,7 +244,7 @@ public static DataLoader newMappedDataLoader(MappedBatchLoaderWithC * (batching, caching and unlimited batch size) where the batch loader function returns a list of * {@link org.dataloader.Try} objects. *

- * If its important you to know the exact status of each item in a batch call and whether it threw exceptions then + * If it's important you to know the exact status of each item in a batch call and whether it threw exceptions then * you can use this form to create the data loader. *

* Using Try objects allows you to capture a value returned or an exception that might diff --git a/src/main/java/org/dataloader/DataLoaderHelper.java b/src/main/java/org/dataloader/DataLoaderHelper.java index 066214c..1e48a94 100644 --- a/src/main/java/org/dataloader/DataLoaderHelper.java +++ b/src/main/java/org/dataloader/DataLoaderHelper.java @@ -34,8 +34,8 @@ import static org.dataloader.impl.Assertions.nonNull; /** - * This helps break up the large DataLoader class functionality and it contains the logic to dispatch the - * promises on behalf of its peer dataloader + * This helps break up the large DataLoader class functionality, and it contains the logic to dispatch the + * promises on behalf of its peer dataloader. * * @param the type of keys * @param the type of values @@ -148,13 +148,11 @@ CompletableFuture load(K key, Object loadContext) { } } - @SuppressWarnings("unchecked") Object getCacheKey(K key) { return loaderOptions.cacheKeyFunction().isPresent() ? loaderOptions.cacheKeyFunction().get().getKey(key) : key; } - @SuppressWarnings("unchecked") Object getCacheKeyWithContext(K key, Object context) { return loaderOptions.cacheKeyFunction().isPresent() ? loaderOptions.cacheKeyFunction().get().getKeyWithContext(key, context) : key; @@ -213,9 +211,9 @@ DispatchResult dispatch() { private CompletableFuture> sliceIntoBatchesOfBatches(List keys, List> queuedFutures, List callContexts, int maxBatchSize) { // the number of keys is > than what the batch loader function can accept // so make multiple calls to the loader - List>> allBatches = new ArrayList<>(); int len = keys.size(); int batchCount = (int) Math.ceil(len / (double) maxBatchSize); + List>> allBatches = new ArrayList<>(batchCount); for (int i = 0; i < batchCount; i++) { int fromIndex = i * maxBatchSize; @@ -296,9 +294,9 @@ private void possiblyClearCacheEntriesOnExceptions(List keys) { if (keys.isEmpty()) { return; } - // by default we don't clear the cached view of this entry to avoid - // frequently loading the same error. This works for short lived request caches - // but might work against long lived caches. Hence we have an option that allows + // by default, we don't clear the cached view of this entry to avoid + // frequently loading the same error. This works for short-lived request caches + // but might work against long-lived caches. Hence, we have an option that allows // it to be cleared if (!loaderOptions.cachingExceptionsEnabled()) { keys.forEach(dataLoader::clear); @@ -384,7 +382,7 @@ CompletableFuture> invokeLoader(List keys, List keyContexts, return completedFuture(assembledValues); } else { // - // we missed some of the keys from cache, so send them to the batch loader + // we missed some keys from cache, so send them to the batch loader // and then fill in their values // CompletableFuture> batchLoad = invokeLoader(missedKeys, missedKeyContexts); @@ -477,7 +475,7 @@ private CompletableFuture> invokeMapBatchLoader(List keys, BatchLoade } CompletableFuture> mapBatchLoad = nonNull(loadResult, () -> "Your batch loader function MUST return a non null CompletionStage").toCompletableFuture(); return mapBatchLoad.thenApply(map -> { - List values = new ArrayList<>(); + List values = new ArrayList<>(keys.size()); for (K key : keys) { V value = map.get(key); values.add(value); diff --git a/src/main/java/org/dataloader/DataLoaderOptions.java b/src/main/java/org/dataloader/DataLoaderOptions.java index bac9476..b96e785 100644 --- a/src/main/java/org/dataloader/DataLoaderOptions.java +++ b/src/main/java/org/dataloader/DataLoaderOptions.java @@ -135,8 +135,8 @@ public DataLoaderOptions setCachingEnabled(boolean cachingEnabled) { /** * Option that determines whether to cache exceptional values (the default), or not. * - * For short lived caches (that is request caches) it makes sense to cache exceptions since - * its likely the key is still poisoned. However if you have long lived caches, then it may make + * For short-lived caches (that is request caches) it makes sense to cache exceptions since + * it's likely the key is still poisoned. However, if you have long-lived caches, then it may make * sense to set this to false since the downstream system may have recovered from its failure * mode. * @@ -147,7 +147,7 @@ public boolean cachingExceptionsEnabled() { } /** - * Sets the option that determines whether exceptional values are cachedis enabled. + * Sets the option that determines whether exceptional values are cache enabled. * * @param cachingExceptionsEnabled {@code true} to enable caching exceptional values, {@code false} otherwise * @@ -236,7 +236,7 @@ public StatisticsCollector getStatisticsCollector() { /** * Sets the statistics collector supplier that will be used with these data loader options. Since it uses - * the supplier pattern, you can create a new statistics collector on each call or you can reuse + * the supplier pattern, you can create a new statistics collector on each call, or you can reuse * a common value * * @param statisticsCollector the statistics collector to use diff --git a/src/main/java/org/dataloader/DataLoaderRegistry.java b/src/main/java/org/dataloader/DataLoaderRegistry.java index 0bc54cb..5a3f90f 100644 --- a/src/main/java/org/dataloader/DataLoaderRegistry.java +++ b/src/main/java/org/dataloader/DataLoaderRegistry.java @@ -127,7 +127,7 @@ public Set getKeys() { } /** - * This will called {@link org.dataloader.DataLoader#dispatch()} on each of the registered + * This will be called {@link org.dataloader.DataLoader#dispatch()} on each of the registered * {@link org.dataloader.DataLoader}s */ public void dispatchAll() { @@ -197,7 +197,7 @@ public Builder register(String key, DataLoader dataLoader) { } /** - * This will combine together the data loaders in this builder with the ones + * This will combine the data loaders in this builder with the ones * from a previous {@link DataLoaderRegistry} * * @param otherRegistry the previous {@link DataLoaderRegistry} diff --git a/src/main/java/org/dataloader/MappedBatchLoader.java b/src/main/java/org/dataloader/MappedBatchLoader.java index 4b489fa..5a7a1a6 100644 --- a/src/main/java/org/dataloader/MappedBatchLoader.java +++ b/src/main/java/org/dataloader/MappedBatchLoader.java @@ -16,13 +16,12 @@ package org.dataloader; -import java.util.List; import java.util.Map; import java.util.Set; import java.util.concurrent.CompletionStage; /** - * A function that is invoked for batch loading a map of of data values indicated by the provided set of keys. The + * A function that is invoked for batch loading a map of data values indicated by the provided set of keys. The * function returns a promise of a map of results of individual load requests. *

* There are a few constraints that must be upheld: diff --git a/src/main/java/org/dataloader/MappedBatchLoaderWithContext.java b/src/main/java/org/dataloader/MappedBatchLoaderWithContext.java index 6e3a2f0..7438d20 100644 --- a/src/main/java/org/dataloader/MappedBatchLoaderWithContext.java +++ b/src/main/java/org/dataloader/MappedBatchLoaderWithContext.java @@ -16,7 +16,6 @@ package org.dataloader; -import java.util.List; import java.util.Map; import java.util.Set; import java.util.concurrent.CompletionStage; diff --git a/src/main/java/org/dataloader/Try.java b/src/main/java/org/dataloader/Try.java index c7eac67..cd33afd 100644 --- a/src/main/java/org/dataloader/Try.java +++ b/src/main/java/org/dataloader/Try.java @@ -15,7 +15,7 @@ /** * Try is class that allows you to hold the result of computation or the throwable it produced. * - * This class is useful in {@link org.dataloader.BatchLoader}s so you can mix a batch of calls where some of + * This class is useful in {@link org.dataloader.BatchLoader}s so you can mix a batch of calls where some * the calls succeeded and some of them failed. You would make your batch loader declaration like : * *

@@ -89,8 +89,8 @@ public static  Try failed(Throwable throwable) {
     }
 
     /**
-     * This returns a Try that has always failed with an consistent exception.  Use this when
-     * yiu dont care about the exception but only that the Try failed.
+     * This returns a Try that has always failed with a consistent exception.  Use this when
+     * you don't care about the exception but only that the Try failed.
      *
      * @param  the type of value
      *
diff --git a/src/main/java/org/dataloader/ValueCache.java b/src/main/java/org/dataloader/ValueCache.java
index 551dc5d..a8dabb1 100644
--- a/src/main/java/org/dataloader/ValueCache.java
+++ b/src/main/java/org/dataloader/ValueCache.java
@@ -15,11 +15,11 @@
  * 

* It differs from {@link CacheMap} which is in fact a cache of promised values aka {@link CompletableFuture}<V>'s. *

- * {@link ValueCache} is more suited to be a wrapper of a long-lived or externallly cached values. {@link CompletableFuture}s cant + * {@link ValueCache} is more suited to be a wrapper of a long-lived or externally cached values. {@link CompletableFuture}s can't * be easily placed in an external cache outside the JVM say, hence the need for the {@link ValueCache}. *

* {@link DataLoader}s use a two stage cache strategy if caching is enabled. If the {@link CacheMap} already has the promise to a value - * that is used. If not then the {@link ValueCache} is asked for a value, if it has one then that is returned (and cached as a promise in the {@link CacheMap}. + * that is used. If not then the {@link ValueCache} is asked for a value, if it has one then that is returned (and cached as a promise in the {@link CacheMap}). *

* If there is no value then the key is queued and loaded via the {@link BatchLoader} calls. The returned values will then be stored in * the {@link ValueCache} and the promises to those values are also stored in the {@link CacheMap}. @@ -29,7 +29,7 @@ * out of the box. *

* The API signature uses {@link CompletableFuture}s because the backing implementation MAY be a remote external cache - * and hence exceptions may happen in retrieving values and they may take time to complete. + * and hence exceptions may happen in retrieving values, and they may take time to complete. * * @param the type of cache keys * @param the type of cache values @@ -67,8 +67,8 @@ static ValueCache defaultValueCache() { CompletableFuture get(K key); /** - * Gets the specified keys from the value cache, in a batch call. If your underlying cache cant do batch caching retrieval - * then do not implement this method and it will delegate back to {@link #get(Object)} for you + * Gets the specified keys from the value cache, in a batch call. If your underlying cache cannot do batch caching retrieval + * then do not implement this method, and it will delegate back to {@link #get(Object)} for you *

* Each item in the returned list of values is a {@link Try}. If the key could not be found then a failed Try just be returned otherwise * a successful Try contain the cached value is returned. @@ -104,8 +104,8 @@ default CompletableFuture>> getValues(List keys) throws ValueCach CompletableFuture set(K key, V value); /** - * Stores the value with the specified keys, or updates it if the keys if they already exist. If your underlying cache cant do batch caching setting - * then do not implement this method and it will delegate back to {@link #set(Object, Object)} for you + * Stores the value with the specified keys, or updates it if the keys if they already exist. If your underlying cache can't do batch caching setting + * then do not implement this method, and it will delegate back to {@link #set(Object, Object)} for you * * @param keys the keys to store * @param values the values to store @@ -115,7 +115,7 @@ default CompletableFuture>> getValues(List keys) throws ValueCach * @throws ValueCachingNotSupported if this cache wants to short-circuit this method completely */ default CompletableFuture> setValues(List keys, List values) throws ValueCachingNotSupported { - List> cacheSets = new ArrayList<>(); + List> cacheSets = new ArrayList<>(keys.size()); for (int i = 0; i < keys.size(); i++) { K k = keys.get(i); V v = values.get(i); diff --git a/src/main/java/org/dataloader/ValueCacheOptions.java b/src/main/java/org/dataloader/ValueCacheOptions.java index 1a0c1a1..7e2f025 100644 --- a/src/main/java/org/dataloader/ValueCacheOptions.java +++ b/src/main/java/org/dataloader/ValueCacheOptions.java @@ -22,7 +22,7 @@ public static ValueCacheOptions newOptions() { /** * This controls whether the {@link DataLoader} will wait for the {@link ValueCache#set(Object, Object)} call - * to complete before it completes the returned value. By default this is false and hence + * to complete before it completes the returned value. By default, this is false and hence * the {@link ValueCache#set(Object, Object)} call may complete some time AFTER the data loader * value has been returned. * diff --git a/src/main/java/org/dataloader/annotations/ExperimentalApi.java b/src/main/java/org/dataloader/annotations/ExperimentalApi.java index 6be889e..782998e 100644 --- a/src/main/java/org/dataloader/annotations/ExperimentalApi.java +++ b/src/main/java/org/dataloader/annotations/ExperimentalApi.java @@ -14,7 +14,7 @@ * This represents code that the graphql-java project considers experimental API and while our intention is that it will * progress to be {@link PublicApi}, its existence, signature of behavior may change between releases. * - * In general unnecessary changes will be avoided but you should not depend on experimental classes being stable + * In general unnecessary changes will be avoided, but you should not depend on experimental classes being stable */ @Retention(RetentionPolicy.RUNTIME) @Target(value = {CONSTRUCTOR, METHOD, TYPE, FIELD}) diff --git a/src/main/java/org/dataloader/annotations/Internal.java b/src/main/java/org/dataloader/annotations/Internal.java index 4ad04cd..51cfef2 100644 --- a/src/main/java/org/dataloader/annotations/Internal.java +++ b/src/main/java/org/dataloader/annotations/Internal.java @@ -13,7 +13,7 @@ * This represents code that the java-dataloader project considers internal code that MAY not be stable within * major releases. * - * In general unnecessary changes will be avoided but you should not depend on internal classes being stable + * In general unnecessary changes will be avoided, but you should not depend on internal classes being stable */ @Retention(RetentionPolicy.RUNTIME) @Target(value = {CONSTRUCTOR, METHOD, TYPE, FIELD}) diff --git a/src/main/java/org/dataloader/annotations/PublicSpi.java b/src/main/java/org/dataloader/annotations/PublicSpi.java index 5f385b7..7384fa9 100644 --- a/src/main/java/org/dataloader/annotations/PublicSpi.java +++ b/src/main/java/org/dataloader/annotations/PublicSpi.java @@ -15,7 +15,7 @@ * * The guarantee is for callers of code with this annotation as well as derivations that inherit / implement this code. * - * New methods will not be added (without using default methods say) that would nominally breaks SPI implementations + * New methods will not be added (without using default methods say) that would nominally break SPI implementations * within a major release. */ @Retention(RetentionPolicy.RUNTIME) diff --git a/src/main/java/org/dataloader/annotations/VisibleForTesting.java b/src/main/java/org/dataloader/annotations/VisibleForTesting.java index 99f97f0..a391113 100644 --- a/src/main/java/org/dataloader/annotations/VisibleForTesting.java +++ b/src/main/java/org/dataloader/annotations/VisibleForTesting.java @@ -9,7 +9,7 @@ import static java.lang.annotation.ElementType.METHOD; /** - * Marks fields, methods etc as more visible than actually needed for testing purposes. + * Marks fields, methods etc. as more visible than actually needed for testing purposes. */ @Retention(RetentionPolicy.RUNTIME) @Target(value = {CONSTRUCTOR, METHOD, FIELD}) diff --git a/src/main/java/org/dataloader/impl/PromisedValues.java b/src/main/java/org/dataloader/impl/PromisedValues.java index 89ae8de..ab75044 100644 --- a/src/main/java/org/dataloader/impl/PromisedValues.java +++ b/src/main/java/org/dataloader/impl/PromisedValues.java @@ -12,11 +12,11 @@ import static java.util.Arrays.asList; /** - * This allows multiple {@link CompletionStage}s to be combined together and completed + * This allows multiple {@link CompletionStage}s to be combined and completed * as one and should something go wrong, instead of throwing {@link CompletionException}s it captures the cause and returns null for that - * data value, other wise it allows you to access them as a list of values. + * data value, otherwise it allows you to access them as a list of values. *

- * This class really encapsulate a list of promised values. It is considered finished when all of the underlying futures + * This class really encapsulate a list of promised values. It is considered finished when all the underlying futures * are finished. *

* You can get that list of values via {@link #toList()}. You can also compose a {@link CompletableFuture} of that @@ -28,7 +28,7 @@ public interface PromisedValues { /** - * Returns a new {@link PromisedValues} that is completed when all of + * Returns a new {@link PromisedValues} that is completed when all * the given {@link CompletionStage}s complete. If any of the given * {@link CompletionStage}s complete exceptionally, then the returned * {@link PromisedValues} also does so. @@ -43,7 +43,7 @@ static PromisedValues allOf(List> cfs) { } /** - * Returns a new {@link PromisedValues} that is completed when all of + * Returns a new {@link PromisedValues} that is completed when all * the given {@link CompletionStage}s complete. If any of the given * {@link CompletionStage}s complete exceptionally, then the returned * {@link PromisedValues} also does so. @@ -59,7 +59,7 @@ static PromisedValues allOf(CompletionStage f1, CompletionStage f2) } /** - * Returns a new {@link PromisedValues} that is completed when all of + * Returns a new {@link PromisedValues} that is completed when all * the given {@link CompletionStage}s complete. If any of the given * {@link CompletionStage}s complete exceptionally, then the returned * {@link PromisedValues} also does so. @@ -77,7 +77,7 @@ static PromisedValues allOf(CompletionStage f1, CompletionStage f2, /** - * Returns a new {@link PromisedValues} that is completed when all of + * Returns a new {@link PromisedValues} that is completed when all * the given {@link CompletionStage}s complete. If any of the given * {@link CompletionStage}s complete exceptionally, then the returned * {@link PromisedValues} also does so. @@ -96,7 +96,7 @@ static PromisedValues allOf(CompletionStage f1, CompletionStage f2, /** - * Returns a new {@link PromisedValues} that is completed when all of + * Returns a new {@link PromisedValues} that is completed when all * the given {@link PromisedValues}s complete. If any of the given * {@link PromisedValues}s complete exceptionally, then the returned * {@link PromisedValues} also does so. @@ -111,7 +111,7 @@ static PromisedValues allPromisedValues(List> cfs) { } /** - * Returns a new {@link PromisedValues} that is completed when all of + * Returns a new {@link PromisedValues} that is completed when all * the given {@link PromisedValues}s complete. If any of the given * {@link PromisedValues}s complete exceptionally, then the returned * {@link PromisedValues} also does so. @@ -127,7 +127,7 @@ static PromisedValues allPromisedValues(PromisedValues pv1, PromisedVa } /** - * Returns a new {@link PromisedValues} that is completed when all of + * Returns a new {@link PromisedValues} that is completed when all * the given {@link PromisedValues}s complete. If any of the given * {@link PromisedValues}s complete exceptionally, then the returned * {@link PromisedValues} also does so. @@ -144,7 +144,7 @@ static PromisedValues allPromisedValues(PromisedValues pv1, PromisedVa } /** - * Returns a new {@link PromisedValues} that is completed when all of + * Returns a new {@link PromisedValues} that is completed when all * the given {@link PromisedValues}s complete. If any of the given * {@link PromisedValues}s complete exceptionally, then the returned * {@link PromisedValues} also does so. @@ -177,7 +177,7 @@ static PromisedValues allPromisedValues(PromisedValues pv1, PromisedVa boolean succeeded(); /** - * @return true if any of the the futures completed unsuccessfully + * @return true if any of the futures completed unsuccessfully */ boolean failed(); @@ -220,7 +220,6 @@ static PromisedValues allPromisedValues(PromisedValues pv1, PromisedVa * * @return the value of the future */ - @SuppressWarnings("unchecked") T get(int index); /** diff --git a/src/main/java/org/dataloader/impl/PromisedValuesImpl.java b/src/main/java/org/dataloader/impl/PromisedValuesImpl.java index 2ba592b..ddaba81 100644 --- a/src/main/java/org/dataloader/impl/PromisedValuesImpl.java +++ b/src/main/java/org/dataloader/impl/PromisedValuesImpl.java @@ -25,7 +25,7 @@ public class PromisedValuesImpl implements PromisedValues { private PromisedValuesImpl(List> cs) { this.futures = nonNull(cs); this.cause = new AtomicReference<>(); - CompletableFuture[] futuresArray = cs.stream().map(CompletionStage::toCompletableFuture).toArray(CompletableFuture[]::new); + CompletableFuture[] futuresArray = cs.stream().map(CompletionStage::toCompletableFuture).toArray(CompletableFuture[]::new); this.controller = CompletableFuture.allOf(futuresArray).handle((result, throwable) -> { setCause(throwable); return null; diff --git a/src/main/java/org/dataloader/registries/DispatchPredicate.java b/src/main/java/org/dataloader/registries/DispatchPredicate.java index 247a51a..677f484 100644 --- a/src/main/java/org/dataloader/registries/DispatchPredicate.java +++ b/src/main/java/org/dataloader/registries/DispatchPredicate.java @@ -73,7 +73,7 @@ default DispatchPredicate or(DispatchPredicate other) { } /** - * This predicate will return true if the {@link DataLoader} has not be dispatched + * This predicate will return true if the {@link DataLoader} has not been dispatched * for at least the duration length of time. * * @param duration the length of time to check diff --git a/src/main/java/org/dataloader/registries/ScheduledDataLoaderRegistry.java b/src/main/java/org/dataloader/registries/ScheduledDataLoaderRegistry.java index 28b13e0..6ea9425 100644 --- a/src/main/java/org/dataloader/registries/ScheduledDataLoaderRegistry.java +++ b/src/main/java/org/dataloader/registries/ScheduledDataLoaderRegistry.java @@ -58,6 +58,7 @@ public class ScheduledDataLoaderRegistry extends DataLoaderRegistry implements A private final Map, DispatchPredicate> dataLoaderPredicates = new ConcurrentHashMap<>(); private final DispatchPredicate dispatchPredicate; private final ScheduledExecutorService scheduledExecutorService; + private final boolean defaultExecutorUsed; private final Duration schedule; private final boolean tickerMode; private volatile boolean closed; @@ -66,6 +67,7 @@ private ScheduledDataLoaderRegistry(Builder builder) { super(); this.dataLoaders.putAll(builder.dataLoaders); this.scheduledExecutorService = builder.scheduledExecutorService; + this.defaultExecutorUsed = builder.defaultExecutorUsed; this.schedule = builder.schedule; this.tickerMode = builder.tickerMode; this.closed = false; @@ -79,6 +81,16 @@ private ScheduledDataLoaderRegistry(Builder builder) { @Override public void close() { closed = true; + if (defaultExecutorUsed) { + scheduledExecutorService.shutdown(); + } + } + + /** + * @return executor being used by this registry + */ + public ScheduledExecutorService getScheduledExecutorService() { + return scheduledExecutorService; } /** @@ -198,15 +210,15 @@ public int dispatchAllWithCountImmediately() { /** * This will schedule a task to check the predicate and dispatch if true right now. It will not do - * a pre check of the preodicate like {@link #dispatchAll()} would + * a pre-check of the predicate like {@link #dispatchAll()} would */ public void rescheduleNow() { dataLoaders.forEach(this::reschedule); } /** - * Returns true if the dataloader has a predicate which returned true, OR the overall - * registry predicate returned true. + * If a specific {@link DispatchPredicate} is registered for this dataloader then it uses it values + * otherwise the overall registry predicate is used. * * @param dataLoaderKey the key in the dataloader map * @param dataLoader the dataloader @@ -216,9 +228,7 @@ public void rescheduleNow() { private boolean shouldDispatch(String dataLoaderKey, DataLoader dataLoader) { DispatchPredicate dispatchPredicate = dataLoaderPredicates.get(dataLoader); if (dispatchPredicate != null) { - if (dispatchPredicate.test(dataLoaderKey, dataLoader)) { - return true; - } + return dispatchPredicate.test(dataLoaderKey, dataLoader); } return this.dispatchPredicate.test(dataLoaderKey, dataLoader); } @@ -258,9 +268,18 @@ public static class Builder { private final Map, DispatchPredicate> dataLoaderPredicates = new LinkedHashMap<>(); private DispatchPredicate dispatchPredicate = DispatchPredicate.DISPATCH_ALWAYS; private ScheduledExecutorService scheduledExecutorService; + private boolean defaultExecutorUsed = false; private Duration schedule = Duration.ofMillis(10); private boolean tickerMode = false; + /** + * If you provide a {@link ScheduledExecutorService} then it will NOT be shutdown when + * {@link ScheduledDataLoaderRegistry#close()} is called. This is left to the code that made this setup code + * + * @param executorService the executor service to run the ticker on + * + * @return this builder for a fluent pattern + */ public Builder scheduledExecutorService(ScheduledExecutorService executorService) { this.scheduledExecutorService = nonNull(executorService); return this; @@ -350,6 +369,7 @@ public Builder tickerMode(boolean tickerMode) { public ScheduledDataLoaderRegistry build() { if (scheduledExecutorService == null) { scheduledExecutorService = Executors.newSingleThreadScheduledExecutor(); + defaultExecutorUsed = true; } return new ScheduledDataLoaderRegistry(this); } diff --git a/src/main/java/org/dataloader/scheduler/BatchLoaderScheduler.java b/src/main/java/org/dataloader/scheduler/BatchLoaderScheduler.java index bcebfa0..7cddd54 100644 --- a/src/main/java/org/dataloader/scheduler/BatchLoaderScheduler.java +++ b/src/main/java/org/dataloader/scheduler/BatchLoaderScheduler.java @@ -47,7 +47,7 @@ interface ScheduledMappedBatchLoaderCall { * * @param scheduledCall the callback that needs to be invoked to allow the {@link BatchLoader} to proceed. * @param keys this is the list of keys that will be passed to the {@link BatchLoader}. - * This is provided only for informative reasons and you cant change the keys that are used + * This is provided only for informative reasons, and you can't change the keys that are used * @param environment this is the {@link BatchLoaderEnvironment} in place, * which can be null if it's a simple {@link BatchLoader} call * @param the key type @@ -62,7 +62,7 @@ interface ScheduledMappedBatchLoaderCall { * * @param scheduledCall the callback that needs to be invoked to allow the {@link MappedBatchLoader} to proceed. * @param keys this is the list of keys that will be passed to the {@link MappedBatchLoader}. - * This is provided only for informative reasons and you cant change the keys that are used + * This is provided only for informative reasons and, you can't change the keys that are used * @param environment this is the {@link BatchLoaderEnvironment} in place, * which can be null if it's a simple {@link MappedBatchLoader} call * @param the key type diff --git a/src/main/java/org/dataloader/stats/DelegatingStatisticsCollector.java b/src/main/java/org/dataloader/stats/DelegatingStatisticsCollector.java index f964b29..563d37b 100644 --- a/src/main/java/org/dataloader/stats/DelegatingStatisticsCollector.java +++ b/src/main/java/org/dataloader/stats/DelegatingStatisticsCollector.java @@ -86,7 +86,7 @@ public long incrementCacheHitCount() { } /** - * @return the statistics of the this collector (and not its delegate) + * @return the statistics of the collector (and not its delegate) */ @Override public Statistics getStatistics() { diff --git a/src/main/java/org/dataloader/stats/Statistics.java b/src/main/java/org/dataloader/stats/Statistics.java index 4bc9c69..f5b5e74 100644 --- a/src/main/java/org/dataloader/stats/Statistics.java +++ b/src/main/java/org/dataloader/stats/Statistics.java @@ -54,7 +54,7 @@ public long getLoadCount() { } /** - * @return the number of times the {@link org.dataloader.DataLoader} batch loader function return an specific object that was in error + * @return the number of times the {@link org.dataloader.DataLoader} batch loader function return a specific object that was in error */ public long getLoadErrorCount() { return loadErrorCount; diff --git a/src/main/java/org/dataloader/stats/StatisticsCollector.java b/src/main/java/org/dataloader/stats/StatisticsCollector.java index b32d17e..33e417f 100644 --- a/src/main/java/org/dataloader/stats/StatisticsCollector.java +++ b/src/main/java/org/dataloader/stats/StatisticsCollector.java @@ -122,7 +122,7 @@ default long incrementCacheHitCount(IncrementCacheHitCountStatisticsContext< long incrementCacheHitCount(); /** - * @return the statistics that have been gathered up to this point in time + * @return the statistics that have been gathered to this point in time */ Statistics getStatistics(); } diff --git a/src/test/java/org/dataloader/DataLoaderIfPresentTest.java b/src/test/java/org/dataloader/DataLoaderIfPresentTest.java index 916fdef..1d897f2 100644 --- a/src/test/java/org/dataloader/DataLoaderIfPresentTest.java +++ b/src/test/java/org/dataloader/DataLoaderIfPresentTest.java @@ -34,10 +34,10 @@ public void should_detect_if_present_cf() { assertThat(cachedPromise.get(), sameInstance(future1)); - // but its not done! + // but it's not done! assertThat(cachedPromise.get().isDone(), equalTo(false)); // - // and hence it cant be loaded as complete + // and hence it can't be loaded as complete cachedPromise = dataLoader.getIfCompleted(1); assertThat(cachedPromise.isPresent(), equalTo(false)); } diff --git a/src/test/java/org/dataloader/DataLoaderStatsTest.java b/src/test/java/org/dataloader/DataLoaderStatsTest.java index a76d0f7..c2faa50 100644 --- a/src/test/java/org/dataloader/DataLoaderStatsTest.java +++ b/src/test/java/org/dataloader/DataLoaderStatsTest.java @@ -68,7 +68,7 @@ public void stats_are_collected_by_default() { @Test public void stats_are_collected_with_specified_collector() { - // lets prime it with some numbers so we know its ours + // let's prime it with some numbers, so we know it's ours StatisticsCollector collector = new SimpleStatisticsCollector(); collector.incrementLoadCount(new IncrementLoadCountStatisticsContext<>(1, null)); collector.incrementBatchLoadCountBy(1, new IncrementBatchLoadCountByStatisticsContext<>(1, null)); diff --git a/src/test/java/org/dataloader/DataLoaderTest.java b/src/test/java/org/dataloader/DataLoaderTest.java index 63a834d..18dd6f8 100644 --- a/src/test/java/org/dataloader/DataLoaderTest.java +++ b/src/test/java/org/dataloader/DataLoaderTest.java @@ -144,7 +144,7 @@ public void should_Return_number_of_batched_entries() { DispatchResult dispatchResult = identityLoader.dispatchWithCounts(); await().until(() -> future1.isDone() && future2.isDone()); - assertThat(dispatchResult.getKeysCount(), equalTo(2)); // its two because its the number dispatched (by key) not the load calls + assertThat(dispatchResult.getKeysCount(), equalTo(2)); // its two because it's the number dispatched (by key) not the load calls assertThat(dispatchResult.getPromisedResults().isDone(), equalTo(true)); } diff --git a/src/test/java/org/dataloader/DataLoaderValueCacheTest.java b/src/test/java/org/dataloader/DataLoaderValueCacheTest.java index 38cfe77..2716fae 100644 --- a/src/test/java/org/dataloader/DataLoaderValueCacheTest.java +++ b/src/test/java/org/dataloader/DataLoaderValueCacheTest.java @@ -174,7 +174,7 @@ public CompletableFuture get(String key) { assertThat(fA.join(), equalTo("a")); assertThat(fB.join(), equalTo("From Cache")); - // a was not in cache (according to get) and hence needed to be loaded + // "a" was not in cache (according to get) and hence needed to be loaded assertThat(loadCalls, equalTo(singletonList(singletonList("a")))); } @@ -201,7 +201,7 @@ public CompletableFuture set(String key, Object value) { assertThat(fA.join(), equalTo("a")); assertThat(fB.join(), equalTo("b")); - // a was not in cache (according to get) and hence needed to be loaded + // "a" was not in cache (according to get) and hence needed to be loaded assertThat(loadCalls, equalTo(singletonList(asList("a", "b")))); assertArrayEquals(customValueCache.store.keySet().toArray(), singletonList("b").toArray()); } @@ -288,7 +288,7 @@ public CompletableFuture>> getValues(List keys) { assertThat(loadCalls, equalTo(singletonList(asList("missC", "missD")))); List values = new ArrayList<>(customValueCache.asMap().values()); - // it will only set back in values that are missed - it wont set in values that successfully + // it will only set back in values that are missed - it won't set in values that successfully // came out of the cache assertThat(values, equalTo(asList("missC", "missD"))); } diff --git a/src/test/java/org/dataloader/TryTest.java b/src/test/java/org/dataloader/TryTest.java index 1fdd286..4da7bca 100644 --- a/src/test/java/org/dataloader/TryTest.java +++ b/src/test/java/org/dataloader/TryTest.java @@ -15,7 +15,6 @@ import static org.junit.Assert.assertThat; import static org.junit.Assert.assertTrue; -@SuppressWarnings("ConstantConditions") public class TryTest { interface RunThatCanThrow { @@ -33,6 +32,7 @@ private void expectThrowable(RunThatCanThrow runnable, Class sTry, String expectedString) { assertThat(sTry.isSuccess(), equalTo(false)); assertThat(sTry.isFailure(), equalTo(true)); @@ -51,21 +51,21 @@ private void assertSuccess(Try sTry, String expectedStr) { } @Test - public void tryFailed() throws Exception { + public void tryFailed() { Try sTry = Try.failed(new RuntimeException("Goodbye Cruel World")); assertFailure(sTry, "Goodbye Cruel World"); } @Test - public void trySucceeded() throws Exception { + public void trySucceeded() { Try sTry = Try.succeeded("Hello World"); assertSuccess(sTry, "Hello World"); } @Test - public void tryCallable() throws Exception { + public void tryCallable() { Try sTry = Try.tryCall(() -> "Hello World"); assertSuccess(sTry, "Hello World"); @@ -78,7 +78,7 @@ public void tryCallable() throws Exception { } @Test - public void triedStage() throws Exception { + public void triedStage() { CompletionStage> sTry = Try.tryStage(CompletableFuture.completedFuture("Hello World")); sTry.thenAccept(stageTry -> assertSuccess(stageTry, "Hello World")); @@ -93,7 +93,7 @@ public void triedStage() throws Exception { } @Test - public void map() throws Exception { + public void map() { Try iTry = Try.succeeded(666); Try sTry = iTry.map(Object::toString); @@ -106,7 +106,7 @@ public void map() throws Exception { } @Test - public void flatMap() throws Exception { + public void flatMap() { Function> intToStringFunc = i -> Try.succeeded(i.toString()); Try iTry = Try.succeeded(666); @@ -123,7 +123,7 @@ public void flatMap() throws Exception { } @Test - public void toOptional() throws Exception { + public void toOptional() { Try iTry = Try.succeeded(666); Optional optional = iTry.toOptional(); assertThat(optional.isPresent(), equalTo(true)); @@ -135,7 +135,7 @@ public void toOptional() throws Exception { } @Test - public void orElse() throws Exception { + public void orElse() { Try sTry = Try.tryCall(() -> "Hello World"); String result = sTry.orElse("other"); @@ -147,7 +147,7 @@ public void orElse() throws Exception { } @Test - public void orElseGet() throws Exception { + public void orElseGet() { Try sTry = Try.tryCall(() -> "Hello World"); String result = sTry.orElseGet(() -> "other"); @@ -159,7 +159,7 @@ public void orElseGet() throws Exception { } @Test - public void reThrow() throws Exception { + public void reThrow() { Try sTry = Try.failed(new RuntimeException("Goodbye Cruel World")); expectThrowable(sTry::reThrow, RuntimeException.class); @@ -169,7 +169,7 @@ public void reThrow() throws Exception { } @Test - public void forEach() throws Exception { + public void forEach() { AtomicReference sRef = new AtomicReference<>(); Try sTry = Try.tryCall(() -> "Hello World"); sTry.forEach(sRef::set); @@ -183,7 +183,7 @@ public void forEach() throws Exception { } @Test - public void recover() throws Exception { + public void recover() { Try sTry = Try.failed(new RuntimeException("Goodbye Cruel World")); sTry = sTry.recover(t -> "Hello World"); diff --git a/src/test/java/org/dataloader/fixtures/TestKit.java b/src/test/java/org/dataloader/fixtures/TestKit.java index ac29a0c..adffb06 100644 --- a/src/test/java/org/dataloader/fixtures/TestKit.java +++ b/src/test/java/org/dataloader/fixtures/TestKit.java @@ -15,7 +15,6 @@ import java.util.LinkedHashSet; import java.util.HashMap; import java.util.List; -import java.util.Set; import java.util.Map; import java.util.Set; import java.util.concurrent.CompletableFuture; @@ -34,7 +33,7 @@ public static BatchLoaderWithContext keysAsValuesWithContext() { } public static MappedBatchLoader keysAsMapOfValues() { - return keys -> mapOfKeys(keys); + return TestKit::mapOfKeys; } public static MappedBatchLoaderWithContext keysAsMapOfValuesWithContext() { @@ -124,6 +123,7 @@ public static List sort(Collection collection) { return collection.stream().sorted().collect(toList()); } + @SafeVarargs public static Set asSet(T... elements) { return new LinkedHashSet<>(Arrays.asList(elements)); } diff --git a/src/test/java/org/dataloader/impl/PromisedValuesImplTest.java b/src/test/java/org/dataloader/impl/PromisedValuesImplTest.java index cbf8cc8..3c9ce65 100644 --- a/src/test/java/org/dataloader/impl/PromisedValuesImplTest.java +++ b/src/test/java/org/dataloader/impl/PromisedValuesImplTest.java @@ -186,7 +186,7 @@ public void exceptions_are_captured_and_reported() throws Exception { @Test public void type_generics_compile_as_expected() throws Exception { - PromisedValues pvList = PromisedValues.allOf(Collections.singletonList(new CompletableFuture())); + PromisedValues pvList = PromisedValues.allOf(Collections.singletonList(new CompletableFuture<>())); PromisedValues pvList2 = PromisedValues.allOf(Collections.>singletonList(new CompletableFuture<>())); assertThat(pvList, notNullValue()); diff --git a/src/test/java/org/dataloader/registries/ScheduledDataLoaderRegistryPredicateTest.java b/src/test/java/org/dataloader/registries/ScheduledDataLoaderRegistryPredicateTest.java index 43da82f..4eab564 100644 --- a/src/test/java/org/dataloader/registries/ScheduledDataLoaderRegistryPredicateTest.java +++ b/src/test/java/org/dataloader/registries/ScheduledDataLoaderRegistryPredicateTest.java @@ -139,13 +139,13 @@ public void test_the_registry_overall_predicate_firing_works() { DataLoader dlB = newDataLoader(identityBatchLoader); DataLoader dlC = newDataLoader(identityBatchLoader); - DispatchPredicate predicateOnSix = new CountingDispatchPredicate(6); + DispatchPredicate predicateOnThree = new CountingDispatchPredicate(3); ScheduledDataLoaderRegistry registry = ScheduledDataLoaderRegistry.newScheduledRegistry() - .register("a", dlA, DISPATCH_NEVER) - .register("b", dlB, DISPATCH_NEVER) - .register("c", dlC, DISPATCH_NEVER) - .dispatchPredicate(predicateOnSix) + .register("a", dlA, new CountingDispatchPredicate(99)) + .register("b", dlB, new CountingDispatchPredicate(99)) + .register("c", dlC) // has none + .dispatchPredicate(predicateOnThree) .schedule(Duration.ofHours(1000)) .build(); @@ -160,16 +160,22 @@ public void test_the_registry_overall_predicate_firing_works() { assertThat(cfB.isDone(), equalTo(false)); assertThat(cfC.isDone(), equalTo(false)); - count = registry.dispatchAllWithCount(); // second firing but the overall been asked 6 times already + count = registry.dispatchAllWithCount(); // second firing assertThat(count, equalTo(0)); assertThat(cfA.isDone(), equalTo(false)); assertThat(cfB.isDone(), equalTo(false)); assertThat(cfC.isDone(), equalTo(false)); - count = registry.dispatchAllWithCount(); // third firing but the overall been asked 9 times already - assertThat(count, equalTo(3)); - assertThat(cfA.isDone(), equalTo(true)); - assertThat(cfB.isDone(), equalTo(true)); + count = registry.dispatchAllWithCount(); // third firing + assertThat(count, equalTo(0)); + assertThat(cfA.isDone(), equalTo(false)); + assertThat(cfB.isDone(), equalTo(false)); + assertThat(cfC.isDone(), equalTo(false)); + + count = registry.dispatchAllWithCount(); // fourth firing + assertThat(count, equalTo(1)); + assertThat(cfA.isDone(), equalTo(false)); + assertThat(cfB.isDone(), equalTo(false)); // they wont ever finish until 99 calls assertThat(cfC.isDone(), equalTo(true)); } @@ -217,9 +223,9 @@ public void test_the_registry_overall_predicate_firing_works_when_on_schedule() DispatchPredicate predicateOnTwenty = new CountingDispatchPredicate(20); ScheduledDataLoaderRegistry registry = ScheduledDataLoaderRegistry.newScheduledRegistry() - .register("a", dlA, DISPATCH_NEVER) - .register("b", dlB, DISPATCH_NEVER) - .register("c", dlC, DISPATCH_NEVER) + .register("a", dlA) + .register("b", dlB) + .register("c", dlC) .dispatchPredicate(predicateOnTwenty) .schedule(Duration.ofMillis(5)) .build(); diff --git a/src/test/java/org/dataloader/registries/ScheduledDataLoaderRegistryTest.java b/src/test/java/org/dataloader/registries/ScheduledDataLoaderRegistryTest.java index 5e0cd9a..146c186 100644 --- a/src/test/java/org/dataloader/registries/ScheduledDataLoaderRegistryTest.java +++ b/src/test/java/org/dataloader/registries/ScheduledDataLoaderRegistryTest.java @@ -12,6 +12,7 @@ import java.util.List; import java.util.concurrent.CompletableFuture; import java.util.concurrent.Executors; +import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicInteger; @@ -285,7 +286,7 @@ public void test_can_tick_after_first_dispatch_for_chain_data_loaders() { assertThat(registry.isTickerMode(), equalTo(true)); int count = registry.dispatchAllWithCount(); - assertThat(count,equalTo(1)); + assertThat(count, equalTo(1)); await().atMost(TWO_SECONDS).untilAtomic(done, is(true)); @@ -314,7 +315,7 @@ public void test_chain_data_loaders_will_hang_if_not_in_ticker_mode() { assertThat(registry.isTickerMode(), equalTo(false)); int count = registry.dispatchAllWithCount(); - assertThat(count,equalTo(1)); + assertThat(count, equalTo(1)); try { await().atMost(TWO_SECONDS).untilAtomic(done, is(true)); @@ -323,4 +324,25 @@ public void test_chain_data_loaders_will_hang_if_not_in_ticker_mode() { } registry.close(); } + + public void test_executors_are_shutdown() { + ScheduledDataLoaderRegistry registry = ScheduledDataLoaderRegistry.newScheduledRegistry().build(); + + ScheduledExecutorService executorService = registry.getScheduledExecutorService(); + assertThat(executorService.isShutdown(), equalTo(false)); + registry.close(); + assertThat(executorService.isShutdown(), equalTo(true)); + + executorService = Executors.newSingleThreadScheduledExecutor(); + registry = ScheduledDataLoaderRegistry.newScheduledRegistry() + .scheduledExecutorService(executorService).build(); + + executorService = registry.getScheduledExecutorService(); + assertThat(executorService.isShutdown(), equalTo(false)); + registry.close(); + // if they provide the executor, we don't close it down + assertThat(executorService.isShutdown(), equalTo(false)); + + + } } \ No newline at end of file pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy