DatastoreStorage implements Closeable { long getLimitForCounter(String counterId) throws IOException { if (GLOBAL_RESOURCE_ID.equals(counterId)) { return config().globalConcurrency().orElse(Long.MAX_VALUE); } final Key limitKey = datastore.newKeyFactory().setKind(KIND_COUNTER_LIMIT).newKey(counterId); final Entity limitEntity = datastore.get(limitKey); if (limitEntity == null) { throw new IllegalArgumentException("No limit found in Datastore for " + counterId); } else { return limitEntity.getLong(PROPERTY_LIMIT); } } DatastoreStorage(CheckedDatastore datastore); @VisibleForTesting  DatastoreStorage(CheckedDatastore datastore,
                   Function<CheckedDatastoreTransaction, DatastoreStorageTransaction> storageTransactionFactory,
                   ExecutorService executor, Logger log); @Override void close(); void updateNextNaturalTrigger(WorkflowId workflowId, TriggerInstantSpec triggerSpec); Map<WorkflowId, Workflow> workflows(); Map<WorkflowId, Workflow> workflows(Set<WorkflowId> workflowIds); List<Workflow> workflows(String componentId); T runInTransactionWithRetries(TransactionFunction<T, E> f);  }
@Test public void shouldReturnDefaultGlobalCounterLimit() throws IOException { assertEquals(Long.MAX_VALUE, storage.getLimitForCounter("GLOBAL_STYX_CLUSTER")); }
@Test public void shouldGetExceptionForUnknownCounter() { var exception = assertThrows( IllegalArgumentException.class, () -> storage.getLimitForCounter("bar-resource")); assertThat(exception.getMessage(), is("No limit found in Datastore for bar-resource")); }