/** * Creates an instance without messaging admin support. */ public DefaultAdmin(DatasetFramework dsFramework, NamespaceId namespace, SecureStoreManager secureStoreManager, NamespaceQueryAdmin namespaceQueryAdmin) { this(dsFramework, namespace, secureStoreManager, null, RetryStrategies.noRetry(), null, namespaceQueryAdmin); }
/** * Creates an instance without messaging admin support. */ public DefaultAdmin(DatasetFramework dsFramework, NamespaceId namespace, SecureStoreManager secureStoreManager) { this(dsFramework, namespace, secureStoreManager, null, RetryStrategies.noRetry(), null); }
protected AbstractAppenderContext(DatasetFramework datasetFramework, TransactionSystemClient txClient, LocationFactory locationFactory, MetricsCollectionService metricsCollectionService) { this.locationFactory = locationFactory; // No need to have retry for dataset admin operations // The log framework itself will perform retries and state management this.datasetManager = new DefaultDatasetManager(datasetFramework, NamespaceId.SYSTEM, co.cask.cdap.common.service.RetryStrategies.noRetry(), null); this.transactional = Transactions.createTransactionalWithRetry( Transactions.createTransactional(new MultiThreadDatasetCache( new SystemDatasetInstantiator(datasetFramework), txClient, NamespaceId.SYSTEM, ImmutableMap.<String, String>of(), null, null)), RetryStrategies.retryOnConflict(20, 100) ); this.metricsContext = metricsCollectionService.getContext(Collections.<String, String>emptyMap()); }
protected AbstractAppenderContext(DatasetFramework datasetFramework, TransactionSystemClient txClient, LocationFactory locationFactory, MetricsCollectionService metricsCollectionService) { this.locationFactory = locationFactory; // No need to have retry for dataset admin operations // The log framework itself will perform retries and state management this.datasetManager = new DefaultDatasetManager(datasetFramework, NamespaceId.SYSTEM, co.cask.cdap.common.service.RetryStrategies.noRetry(), null); this.transactional = Transactions.createTransactionalWithRetry( Transactions.createTransactional(new MultiThreadDatasetCache( new SystemDatasetInstantiator(datasetFramework), txClient, NamespaceId.SYSTEM, ImmutableMap.<String, String>of(), null, null)), RetryStrategies.retryOnConflict(20, 100) ); this.metricsContext = metricsCollectionService.getContext(Collections.<String, String>emptyMap()); }
@Test public void testNormalIteration() throws InterruptedException { CountDownLatch latch = new CountDownLatch(5); Service service = new AbstractRetryableScheduledService(RetryStrategies.noRetry()) { @Override protected long runTask() { latch.countDown(); return 1L; } }; service.start(); Assert.assertTrue(latch.await(5, TimeUnit.SECONDS)); service.stopAndWait(); }
@Test public void testRetryExhausted() throws InterruptedException, ExecutionException, TimeoutException { Service service = new AbstractRetryableScheduledService(RetryStrategies.noRetry()) { @Override protected long runTask() throws Exception { throw new Exception("Task failed"); } }; service.start(); // Wait for the service to fail Tasks.waitFor(Service.State.FAILED, service::state, 5, TimeUnit.SECONDS, 10, TimeUnit.MILLISECONDS); try { service.stopAndWait(); } catch (Exception e) { // The root cause should be the one throw from the runTask. It should suppressed the retry exhausted exception. Throwable rootCause = Throwables.getRootCause(e); Assert.assertEquals("Task failed", rootCause.getMessage()); Throwable suppressed = Stream.of(rootCause.getSuppressed()).findFirst().orElseThrow(IllegalStateException::new); Assert.assertTrue(suppressed instanceof RetriesExhaustedException); } }
@Test public void testLoggingContext() { // This test logging context set before the service started is propagated into the service final Map<String, String> context = Collections.singletonMap("key", "value"); // Create the service before setting the context. Service service = new RetryOnStartFailureService(new Supplier<Service>() { @Override public Service get() { return new AbstractIdleService() { @Override protected void startUp() throws Exception { Assert.assertEquals(context, MDC.getCopyOfContextMap()); } @Override protected void shutDown() throws Exception { Assert.assertEquals(context, MDC.getCopyOfContextMap()); } }; } }, RetryStrategies.noRetry()); // Set the MDC context MDC.setContextMap(context); // Start and stop shouldn't throw service.startAndWait(); service.stopAndWait(); }
return RetryStrategies.noRetry();
return RetryStrategies.noRetry();