org.springframework.retry.support.RetryTemplate Java Examples
The following examples show how to use
org.springframework.retry.support.RetryTemplate.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: FeatureFileImporterImpl.java From IridiumApplicationTesting with MIT License | 8 votes |
private String processRemoteUrl(@NotNull final String path) throws IOException { final File copy = File.createTempFile("webapptester", ".feature"); try { final RetryTemplate template = new RetryTemplate(); final SimpleRetryPolicy policy = new SimpleRetryPolicy(); policy.setMaxAttempts(Constants.URL_COPY_RETRIES); template.setRetryPolicy(policy); return template.execute(context -> { FileUtils.copyURLToFile(new URL(path), copy); return FileUtils.readFileToString(copy, Charset.defaultCharset()); }); } finally { FileUtils.deleteQuietly(copy); } }
Example #2
Source File: FeatureFileUtilsImpl.java From IridiumApplicationTesting with MIT License | 8 votes |
private List<File> processRemoteUrl(@NotNull final String path) throws IOException { final File copy = File.createTempFile("webapptester", ".feature"); try { final RetryTemplate template = new RetryTemplate(); final SimpleRetryPolicy policy = new SimpleRetryPolicy(); policy.setMaxAttempts(Constants.URL_COPY_RETRIES); template.setRetryPolicy(policy); template.execute(context -> { FileUtils.copyURLToFile(new URL(path), copy); return null; }); return Arrays.asList(copy); } catch (final FileNotFoundException ex) { /* Don't leave an empty file hanging around */ FileUtils.deleteQuietly(copy); throw new RemoteFeatureException("The remote file could not be downloaded." + " Either the URL was invalid, or the path was actually supposed to reference a" + " local file but that file could not be found an so was assumed to be a URL.", ex); } }
Example #3
Source File: SimpleDemo.java From retry with Apache License 2.0 | 8 votes |
public static void main(String[] args) throws Exception { RetryTemplate template = new RetryTemplate(); // 策略 SimpleRetryPolicy policy = new SimpleRetryPolicy(); policy.setMaxAttempts(2); template.setRetryPolicy(policy); String result = template.execute( new RetryCallback<String, Exception>() { @Override public String doWithRetry(RetryContext arg0) { throw new NullPointerException(); } } , new RecoveryCallback<String>() { @Override public String recover(RetryContext context) { return "recovery callback"; } } ); LOGGER.info("result: {}", result); }
Example #4
Source File: DefaultRetryTemplateConverterTest.java From distributed-lock with MIT License | 6 votes |
private void assertRetryTemplateConstruction(final RetryTemplate retryTemplate, final long timeout, final long backOff) { final var wrapper = PropertyAccessorFactory.forDirectFieldAccess(retryTemplate); assertThat(wrapper.getPropertyValue("retryPolicy")).isInstanceOf(CompositeRetryPolicy.class); assertThat((RetryPolicy[]) wrapper.getPropertyValue("retryPolicy.policies")) .hasSize(2) .anyMatch(policy1 -> { if (policy1 instanceof TimeoutRetryPolicy) { final var timeoutRetryPolicy = (TimeoutRetryPolicy) policy1; assertThat(timeoutRetryPolicy.getTimeout()).isEqualTo(timeout); return true; } return false; }) .anyMatch(policy2 -> { if (policy2 instanceof SimpleRetryPolicy) { final var simpleRetryPolicy = (SimpleRetryPolicy) policy2; assertThat(simpleRetryPolicy.getMaxAttempts()).isEqualTo(Integer.MAX_VALUE); return true; } return false; }); assertThat(wrapper.getPropertyValue("backOffPolicy")).isInstanceOf(FixedBackOffPolicy.class); assertThat(((FixedBackOffPolicy) wrapper.getPropertyValue("backOffPolicy")).getBackOffPeriod()).isEqualTo(backOff); }
Example #5
Source File: MetadataSyncJob.java From dhis2-core with BSD 3-Clause "New" or "Revised" License | 6 votes |
public MetadataSyncJob( SystemSettingManager systemSettingManager, RetryTemplate retryTemplate, SynchronizationManager synchronizationManager, MetadataSyncPreProcessor metadataSyncPreProcessor, MetadataSyncPostProcessor metadataSyncPostProcessor, MetadataSyncService metadataSyncService, MetadataRetryContext metadataRetryContext ) { checkNotNull( systemSettingManager ); checkNotNull( retryTemplate ); checkNotNull( synchronizationManager ); checkNotNull( metadataSyncPreProcessor ); checkNotNull( metadataSyncPostProcessor ); checkNotNull( metadataSyncService ); checkNotNull( metadataRetryContext ); this.systemSettingManager = systemSettingManager; this.retryTemplate = retryTemplate; this.synchronizationManager = synchronizationManager; this.metadataSyncPreProcessor = metadataSyncPreProcessor; this.metadataSyncPostProcessor = metadataSyncPostProcessor; this.metadataSyncService = metadataSyncService; this.metadataRetryContext = metadataRetryContext; }
Example #6
Source File: JobKickoffTask.java From genie with Apache License 2.0 | 6 votes |
/** * Constructor. * * @param runAsUserEnabled Flag that tells if job should be run as user specified in the request * @param userCreationEnabled Flag that tells if the user specified should be created * @param executor An executor object used to run jobs * @param hostname Hostname for the node the job is running on * @param registry The metrics registry to use * @param jobDirectoryManifestCreatorService The manifest creator service */ public JobKickoffTask( final boolean runAsUserEnabled, final boolean userCreationEnabled, @NotNull final Executor executor, @NotNull final String hostname, @NotNull final MeterRegistry registry, final JobDirectoryManifestCreatorService jobDirectoryManifestCreatorService ) { super(registry); this.isRunAsUserEnabled = runAsUserEnabled; this.isUserCreationEnabled = userCreationEnabled; this.executor = executor; this.hostname = hostname; this.jobDirectoryManifestCreatorService = jobDirectoryManifestCreatorService; this.retryTemplate = new RetryTemplate(); this.retryTemplate.setBackOffPolicy(new ExponentialBackOffPolicy()); }
Example #7
Source File: DataServiceRetryAspect.java From genie with Apache License 2.0 | 6 votes |
/** * Constructor. * * @param dataServiceRetryProperties retry properties */ public DataServiceRetryAspect(final DataServiceRetryProperties dataServiceRetryProperties) { this.retryTemplate = new RetryTemplate(); this.retryTemplate.setRetryPolicy( new SimpleRetryPolicy( dataServiceRetryProperties.getNoOfRetries(), new ImmutableMap.Builder<Class<? extends Throwable>, Boolean>() .put(CannotGetJdbcConnectionException.class, true) .put(CannotAcquireLockException.class, true) .put(DeadlockLoserDataAccessException.class, true) .put(OptimisticLockingFailureException.class, true) .put(PessimisticLockingFailureException.class, true) .put(ConcurrencyFailureException.class, true) // Will this work for cases where the write queries timeout on the client? .put(QueryTimeoutException.class, true) .put(TransientDataAccessResourceException.class, true) .put(JpaSystemException.class, true) .build() ) ); final ExponentialBackOffPolicy backOffPolicy = new ExponentialBackOffPolicy(); backOffPolicy.setInitialInterval(dataServiceRetryProperties.getInitialInterval()); backOffPolicy.setMaxInterval(dataServiceRetryProperties.getMaxInterval()); this.retryTemplate.setBackOffPolicy(backOffPolicy); }
Example #8
Source File: RetryTemplateTests.java From spring-cloud-stream with Apache License 2.0 | 6 votes |
@SuppressWarnings("rawtypes") @Test public void testSpecificCustomRetryTemplate() throws Exception { ApplicationContext context = new SpringApplicationBuilder( SpecificCustomRetryTemplateConfiguration.class) .web(WebApplicationType.NONE).run("--spring.jmx.enabled=false", "--spring.cloud.stream.bindings.input.consumer.retry-template-name=retryTemplateTwo"); RetryTemplate retryTemplateTwo = context.getBean("retryTemplateTwo", RetryTemplate.class); BindingServiceProperties bindingServiceProperties = context .getBean(BindingServiceProperties.class); ConsumerProperties consumerProperties = bindingServiceProperties .getConsumerProperties("input"); AbstractBinder binder = context.getBean(AbstractBinder.class); Method m = AbstractBinder.class.getDeclaredMethod("buildRetryTemplate", ConsumerProperties.class); m.setAccessible(true); RetryTemplate retryTemplate = (RetryTemplate) m.invoke(binder, consumerProperties); assertThat(retryTemplate).isEqualTo(retryTemplateTwo); }
Example #9
Source File: ApisAutoConfiguration.java From genie with Apache License 2.0 | 6 votes |
/** * Get RetryTemplate. * * @param retryProperties The http retry properties to use * @return The retry template to use */ @Bean @ConditionalOnMissingBean(name = "genieRetryTemplate") public RetryTemplate genieRetryTemplate(final RetryProperties retryProperties) { final RetryTemplate retryTemplate = new RetryTemplate(); retryTemplate.setRetryPolicy( new SimpleRetryPolicy( retryProperties.getNoOfRetries(), Collections.singletonMap(Exception.class, true) ) ); final ExponentialBackOffPolicy backOffPolicy = new ExponentialBackOffPolicy(); backOffPolicy.setInitialInterval(retryProperties.getInitialInterval()); backOffPolicy.setMaxInterval(retryProperties.getMaxInterval()); retryTemplate.setBackOffPolicy(backOffPolicy); return retryTemplate; }
Example #10
Source File: RetryLoadBalancerInterceptor.java From spring-cloud-commons with Apache License 2.0 | 6 votes |
private RetryTemplate createRetryTemplate(String serviceName, HttpRequest request, LoadBalancedRetryPolicy retryPolicy) { RetryTemplate template = new RetryTemplate(); BackOffPolicy backOffPolicy = this.lbRetryFactory .createBackOffPolicy(serviceName); template.setBackOffPolicy( backOffPolicy == null ? new NoBackOffPolicy() : backOffPolicy); template.setThrowLastExceptionOnExhausted(true); RetryListener[] retryListeners = this.lbRetryFactory .createRetryListeners(serviceName); if (retryListeners != null && retryListeners.length != 0) { template.setListeners(retryListeners); } template.setRetryPolicy(!this.lbProperties.isEnabled() || retryPolicy == null ? new NeverRetryPolicy() : new InterceptorRetryPolicy(request, retryPolicy, this.loadBalancer, serviceName)); return template; }
Example #11
Source File: KafkaTopicProvisioner.java From spring-cloud-stream-binder-kafka with Apache License 2.0 | 6 votes |
@Override public void afterPropertiesSet() { if (this.metadataRetryOperations == null) { RetryTemplate retryTemplate = new RetryTemplate(); SimpleRetryPolicy simpleRetryPolicy = new SimpleRetryPolicy(); simpleRetryPolicy.setMaxAttempts(10); retryTemplate.setRetryPolicy(simpleRetryPolicy); ExponentialBackOffPolicy backOffPolicy = new ExponentialBackOffPolicy(); backOffPolicy.setInitialInterval(100); backOffPolicy.setMultiplier(2); backOffPolicy.setMaxInterval(1000); retryTemplate.setBackOffPolicy(backOffPolicy); this.metadataRetryOperations = retryTemplate; } }
Example #12
Source File: FileContentRetrieval.java From IridiumApplicationTesting with MIT License | 6 votes |
private String retrieveStringFromRemoteFile(@NotNull final String remoteFileName) { checkArgument(StringUtils.isNoneBlank(remoteFileName)); File copy = null; try { copy = File.createTempFile("capabilities", ".tmp"); final File finalCopy = copy; final RetryTemplate template = new RetryTemplate(); final SimpleRetryPolicy policy = new SimpleRetryPolicy(); policy.setMaxAttempts(Constants.URL_COPY_RETRIES); template.setRetryPolicy(policy); template.execute(context -> { FileUtils.copyURLToFile(new URL(remoteFileName), finalCopy, TIMEOUT, TIMEOUT); return null; }); return retrieveStringFromLocalFile(copy.getAbsolutePath()); } catch (final IOException ex) { throw new ConfigurationException(ex); } finally { if (copy != null) { FileUtils.deleteQuietly(copy); } } }
Example #13
Source File: RetryInterceptor.java From mica with GNU Lesser General Public License v3.0 | 6 votes |
@Override public Response intercept(Chain chain) throws IOException { Request request = chain.request(); RetryTemplate template = createRetryTemplate(retryPolicy); return template.execute(context -> { Response response = chain.proceed(request); // 结果集校验 Predicate<ResponseSpec> respPredicate = retryPolicy.getRespPredicate(); if (respPredicate == null) { return response; } // copy 一份 body ResponseBody body = response.peekBody(Long.MAX_VALUE); try (HttpResponse httpResponse = new HttpResponse(response)) { if (respPredicate.test(httpResponse)) { throw new IOException("Http Retry ResponsePredicate test Failure."); } } return response.newBuilder().body(body).build(); }); }
Example #14
Source File: CallWebserviceProcessor.java From batchers with Apache License 2.0 | 5 votes |
@Override public TaxWebserviceCallResult process(TaxCalculation taxCalculation) throws Exception { LOG.info("Web service process: " + taxCalculation); RetryTemplate retryTemplate = retryConfig.createRetryTemplate(); Callable<Void> callable = () -> retryTemplate.execute(doWebserviceCallWithRetryCallback(taxCalculation)); TaxWebserviceCallResult taxWebserviceCallResult = taxPaymentWebServiceFacade.callTaxService(taxCalculation, callable); return taxWebserviceCallResult; }
Example #15
Source File: RabbitMQConfig.java From micro-service with MIT License | 5 votes |
@Bean() @Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE) public RabbitTemplate rabbitTemplate() { ExponentialBackOffPolicy backOffPolicy = new ExponentialBackOffPolicy(); backOffPolicy.setInitialInterval(500); backOffPolicy.setMultiplier(10.0); backOffPolicy.setMaxInterval(10000); RetryTemplate retryTemplate = new RetryTemplate(); retryTemplate.setBackOffPolicy(backOffPolicy); RabbitTemplate template = new RabbitTemplate(connectionFactory()); template.setRetryTemplate(retryTemplate); template.setChannelTransacted(false); template.setConfirmCallback(new ConfirmCallback() { @Override public void confirm(CorrelationData correlationData, boolean ack, String cause) { if(ack) { logger.info("发送消息成功, correlationId={}", correlationData.getId()); } else { logger.info("发送消息失败, correlationId={}, cause={}", correlationData.getId(), cause); } } }); return template; }
Example #16
Source File: RetryConfig.java From batchers with Apache License 2.0 | 5 votes |
public RetryTemplate createRetryTemplate() { Map<Class<? extends Throwable>, Boolean> exceptions = new HashMap<>(); exceptions.put(TaxWebServiceNonFatalException.class, true); RetryTemplate template = new RetryTemplate(); SimpleRetryPolicy retryPolicy = new SimpleRetryPolicy(maxAttempts, exceptions); template.setRetryPolicy(retryPolicy); ExponentialBackOffPolicy backOffPolicy = new ExponentialBackOffPolicy(); backOffPolicy.setInitialInterval(initialInterval); template.setBackOffPolicy(backOffPolicy); return template; }
Example #17
Source File: ExceptionQueueContextConfig.java From sinavi-jfw with Apache License 2.0 | 5 votes |
/** * リトライのポリシー(間隔、回数)を設定し、 * {@link RetryOperations}のインスタンスをDIコンテナに登録します。 * @return {@link RetryTemplate}のインスタンス */ @Bean public RetryOperations retryOperations() { RetryTemplate template = new RetryTemplate(); template.setRetryPolicy(retryPolicy()); template.setBackOffPolicy(backOffPolicy()); return template; }
Example #18
Source File: AmqpContextConfig.java From sinavi-jfw with Apache License 2.0 | 5 votes |
/** * {@link RetryTemplate}のインスタンスをDIコンテナに登録します。 * @return {@link RetryTemplate}のインスタンス */ protected RetryTemplate retryTemplate() { RetryTemplate template = new RetryTemplate(); template.setBackOffPolicy(backOffPolicy()); template.setRetryPolicy(simpleRetryPolicy()); return template; }
Example #19
Source File: RabbitSourceTests.java From spring-cloud-stream-app-starters with Apache License 2.0 | 5 votes |
@Test public void test() throws Exception { Advice[] adviceChain = TestUtils.getPropertyValue(this.container, "adviceChain", Advice[].class); assertEquals(1, adviceChain.length); RetryTemplate retryTemplate = TestUtils.getPropertyValue(adviceChain[0], "retryOperations", RetryTemplate.class); assertEquals(5, TestUtils.getPropertyValue(retryTemplate, "retryPolicy.maxAttempts")); assertEquals(123L, TestUtils.getPropertyValue(retryTemplate, "backOffPolicy.initialInterval")); assertEquals(345L, TestUtils.getPropertyValue(retryTemplate, "backOffPolicy.maxInterval")); assertEquals(1.5, TestUtils.getPropertyValue(retryTemplate, "backOffPolicy.multiplier")); assertEquals("scsapp-testq", this.container.getQueueNames()[0]); assertFalse(TestUtils.getPropertyValue(this.container, "defaultRequeueRejected", Boolean.class)); assertEquals(2, TestUtils.getPropertyValue(this.container, "concurrentConsumers")); assertEquals(3, TestUtils.getPropertyValue(this.container, "maxConcurrentConsumers")); assertEquals(AcknowledgeMode.NONE, TestUtils.getPropertyValue(this.container, "acknowledgeMode")); assertEquals(10, TestUtils.getPropertyValue(this.container, "prefetchCount")); assertEquals(5, TestUtils.getPropertyValue(this.container, "txSize")); this.rabbitTemplate.convertAndSend("", "scsapp-testq", "foo", new MessagePostProcessor() { @Override public org.springframework.amqp.core.Message postProcessMessage( org.springframework.amqp.core.Message message) throws AmqpException { message.getMessageProperties().getHeaders().put("bar", "baz"); return message; } }); Message<?> out = this.messageCollector.forChannel(this.channels.output()).poll(10, TimeUnit.SECONDS); assertNotNull(out); assertEquals("foo", out.getPayload()); assertEquals("baz", out.getHeaders().get("bar")); assertNull(out.getHeaders().get(AmqpHeaders.DELIVERY_MODE)); }
Example #20
Source File: CmApiRetryTemplateConfig.java From cloudbreak with Apache License 2.0 | 5 votes |
@Bean public RetryTemplate cmApiRetryTemplate() { RetryTemplate retryTemplate = new RetryTemplate(); FixedBackOffPolicy fixedBackOffPolicy = new FixedBackOffPolicy(); fixedBackOffPolicy.setBackOffPeriod(BACK_OFF_PERIOD); retryTemplate.setBackOffPolicy(fixedBackOffPolicy); retryTemplate.setRetryPolicy(new ApiExceptionRetryPolicy()); return retryTemplate; }
Example #21
Source File: InitializrStatsAutoConfiguration.java From initializr with Apache License 2.0 | 5 votes |
@Bean @ConditionalOnMissingBean(name = "statsRetryTemplate") RetryTemplate statsRetryTemplate() { RetryTemplate retryTemplate = new RetryTemplate(); ExponentialBackOffPolicy backOffPolicy = new ExponentialBackOffPolicy(); backOffPolicy.setInitialInterval(3000L); backOffPolicy.setMultiplier(3); SimpleRetryPolicy retryPolicy = new SimpleRetryPolicy(this.statsProperties.getElastic().getMaxAttempts(), Collections.singletonMap(Exception.class, true)); retryTemplate.setBackOffPolicy(backOffPolicy); retryTemplate.setRetryPolicy(retryPolicy); return retryTemplate; }
Example #22
Source File: RabbitMQConfiguration.java From cukes with Apache License 2.0 | 5 votes |
@Bean RabbitTemplate rabbitTemplate(org.springframework.amqp.rabbit.connection.ConnectionFactory cf, ObjectMapper mapper) { RabbitTemplate template = new RabbitTemplate(cf); template.setExchange(EXCHANGE_NAME); RetryTemplate retry = new RetryTemplate(); ExponentialBackOffPolicy backOff = new ExponentialBackOffPolicy(); backOff.setInitialInterval(1000); backOff.setMultiplier(1.5); backOff.setMaxInterval(60000); retry.setBackOffPolicy(backOff); template.setRetryTemplate(retry); template.setMessageConverter(new Jackson2JsonMessageConverter(mapper)); return template; }
Example #23
Source File: RabbitBinderTests.java From spring-cloud-stream-binder-rabbit with Apache License 2.0 | 5 votes |
private SimpleMessageListenerContainer verifyContainer(Lifecycle endpoint) { SimpleMessageListenerContainer container; RetryTemplate retry; container = TestUtils.getPropertyValue(endpoint, "messageListenerContainer", SimpleMessageListenerContainer.class); assertThat(container.getAcknowledgeMode()).isEqualTo(AcknowledgeMode.NONE); assertThat(container.getQueueNames()[0]).startsWith("foo.props.0"); assertThat(TestUtils.getPropertyValue(container, "transactional", Boolean.class)) .isFalse(); assertThat(TestUtils.getPropertyValue(container, "concurrentConsumers")) .isEqualTo(2); assertThat(TestUtils.getPropertyValue(container, "maxConcurrentConsumers")) .isEqualTo(3); assertThat(TestUtils.getPropertyValue(container, "defaultRequeueRejected", Boolean.class)).isFalse(); assertThat(TestUtils.getPropertyValue(container, "prefetchCount")).isEqualTo(20); assertThat(TestUtils.getPropertyValue(container, "batchSize")).isEqualTo(10); retry = TestUtils.getPropertyValue(endpoint, "retryTemplate", RetryTemplate.class); assertThat(TestUtils.getPropertyValue(retry, "retryPolicy.maxAttempts")) .isEqualTo(23); assertThat(TestUtils.getPropertyValue(retry, "backOffPolicy.initialInterval")) .isEqualTo(2000L); assertThat(TestUtils.getPropertyValue(retry, "backOffPolicy.maxInterval")) .isEqualTo(20000L); assertThat(TestUtils.getPropertyValue(retry, "backOffPolicy.multiplier")) .isEqualTo(5.0); List<?> requestMatchers = TestUtils.getPropertyValue(endpoint, "headerMapper.requestHeaderMatcher.matchers", List.class); assertThat(requestMatchers).hasSize(1); assertThat(TestUtils.getPropertyValue(requestMatchers.get(0), "pattern")) .isEqualTo("foo"); return container; }
Example #24
Source File: JobStatusWebhookEventListener.java From piper with Apache License 2.0 | 5 votes |
private RetryTemplate createRetryTemplate (Accessor aWebhook) { MapObject retryParams = aWebhook.get("retry",MapObject.class,new MapObject()); RetryTemplate retryTemplate = new RetryTemplate(); ExponentialBackOffPolicy backOffPolicy = new ExponentialBackOffPolicy(); backOffPolicy.setInitialInterval(retryParams.getDuration("initialInterval", "2s").toMillis()); backOffPolicy.setMaxInterval(retryParams.getDuration("maxInterval", "30s").toMillis()); backOffPolicy.setMultiplier(retryParams.getDouble("multiplier",2.0)); retryTemplate.setBackOffPolicy(backOffPolicy); SimpleRetryPolicy retryPolicy = new SimpleRetryPolicy(); retryPolicy.setMaxAttempts(retryParams.getInteger("maxAttempts", 5)); retryTemplate.setRetryPolicy(retryPolicy); return retryTemplate; }
Example #25
Source File: InitializrStatsAutoConfigurationTests.java From initializr with Apache License 2.0 | 5 votes |
@Test void statsRetryTemplateConditionalOnMissingBean() { this.contextRunner.withUserConfiguration(CustomStatsRetryTemplateConfiguration.class) .withPropertyValues("initializr.stats.elastic.uri=http://localhost:9200").run((context) -> { assertThat(context).hasSingleBean(RetryTemplate.class); RetryTemplate retryTemplate = context.getBean(RetryTemplate.class); ExponentialBackOffPolicy backOffPolicy = (ExponentialBackOffPolicy) ReflectionTestUtils .getField(retryTemplate, "backOffPolicy"); assertThat(backOffPolicy.getMultiplier()).isEqualTo(10); }); }
Example #26
Source File: AutoCreateTopicDisabledTests.java From spring-cloud-stream-binder-kafka with Apache License 2.0 | 5 votes |
@Test public void testAutoCreateTopicDisabledFailsOnProducerIfTopicNonExistentOnBroker() throws Throwable { KafkaProperties kafkaProperties = new TestKafkaProperties(); kafkaProperties.setBootstrapServers(Collections .singletonList(embeddedKafka.getEmbeddedKafka().getBrokersAsString())); KafkaBinderConfigurationProperties configurationProperties = new KafkaBinderConfigurationProperties( kafkaProperties); // disable auto create topic on the binder. configurationProperties.setAutoCreateTopics(false); // reduce the wait time on the producer blocking operations. configurationProperties.getConfiguration().put("max.block.ms", "3000"); KafkaTopicProvisioner provisioningProvider = new KafkaTopicProvisioner( configurationProperties, kafkaProperties); SimpleRetryPolicy simpleRetryPolicy = new SimpleRetryPolicy(1); final RetryTemplate metadataRetryOperations = new RetryTemplate(); metadataRetryOperations.setRetryPolicy(simpleRetryPolicy); provisioningProvider.setMetadataRetryOperations(metadataRetryOperations); KafkaMessageChannelBinder binder = new KafkaMessageChannelBinder( configurationProperties, provisioningProvider); final String testTopicName = "nonExistent" + System.currentTimeMillis(); ExtendedProducerProperties<KafkaProducerProperties> properties = new ExtendedProducerProperties<>( new KafkaProducerProperties()); expectedException.expect(BinderException.class); expectedException.expectCause(isA(UnknownTopicOrPartitionException.class)); binder.bindProducer(testTopicName, new DirectChannel(), properties); }
Example #27
Source File: AutoCreateTopicDisabledTests.java From spring-cloud-stream-binder-kafka with Apache License 2.0 | 5 votes |
@Test public void testAutoCreateTopicDisabledFailsOnConsumerIfTopicNonExistentOnBroker() throws Throwable { KafkaProperties kafkaProperties = new TestKafkaProperties(); kafkaProperties.setBootstrapServers(Collections .singletonList(embeddedKafka.getEmbeddedKafka().getBrokersAsString())); KafkaBinderConfigurationProperties configurationProperties = new KafkaBinderConfigurationProperties( kafkaProperties); // disable auto create topic on the binder. configurationProperties.setAutoCreateTopics(false); KafkaTopicProvisioner provisioningProvider = new KafkaTopicProvisioner( configurationProperties, kafkaProperties); provisioningProvider.setMetadataRetryOperations(new RetryTemplate()); KafkaMessageChannelBinder binder = new KafkaMessageChannelBinder( configurationProperties, provisioningProvider); final String testTopicName = "nonExistent" + System.currentTimeMillis(); ExtendedConsumerProperties<KafkaConsumerProperties> properties = new ExtendedConsumerProperties<>( new KafkaConsumerProperties()); expectedException.expect(BinderException.class); expectedException.expectCause(isA(UnknownTopicOrPartitionException.class)); binder.createConsumerEndpoint(() -> testTopicName, "group", properties); }
Example #28
Source File: ProjectGenerationStatPublisher.java From initializr with Apache License 2.0 | 5 votes |
public ProjectGenerationStatPublisher(ProjectRequestDocumentFactory documentFactory, StatsProperties statsProperties, RestTemplateBuilder restTemplateBuilder, RetryTemplate retryTemplate) { this.documentFactory = documentFactory; this.objectMapper = createObjectMapper(); StatsProperties.Elastic elastic = statsProperties.getElastic(); UriComponentsBuilder uriBuilder = UriComponentsBuilder.fromUri(determineEntityUrl(elastic)); this.restTemplate = configureAuthorization(restTemplateBuilder, elastic, uriBuilder).build(); this.requestUrl = uriBuilder.userInfo(null).build().toUri(); this.retryTemplate = retryTemplate; }
Example #29
Source File: BrowserInteropUtilsImpl.java From IridiumApplicationTesting with MIT License | 5 votes |
@Override public void setWindowSize(final int width, final int height) { final WebDriver webDriver = State.getThreadDesiredCapabilityMap().getWebDriverForThread(); final boolean isChrome = browserDetection.isChrome(webDriver); final boolean isAndroid = browserDetection.isAndroid(webDriver); final boolean isIPad = browserDetection.isIPad(webDriver); final boolean isIPhone = browserDetection.isIPhone(webDriver); if (!disableInterop()) { if (isAndroid || isIPad || isIPhone) { LOGGER.info("WEBAPPTESTER-INFO-0010: Detected an Android, iPhone or iPad browser. " + "Setting the window size on these browsers is not supported."); } else if (isChrome) { /* This step will sometimes fail in Chrome, so retry a few times in the event of an error because it doesn't matter if we resize a few times. https://github.com/SeleniumHQ/selenium/issues/1853 */ final RetryTemplate template = retryService.getRetryTemplate(); template.execute(context -> { webDriver.manage().window().setPosition(new Point(0, 0)); webDriver.manage().window().setSize(new Dimension(width, height)); return null; }); } } else { webDriver.manage().window().setSize(new Dimension(width, height)); } }
Example #30
Source File: AggregateCounterSinkStoreConfiguration.java From spring-cloud-stream-app-starters with Apache License 2.0 | 5 votes |
@Bean public RetryOperations retryOperations() { RetryTemplate retryTemplate = new RetryTemplate(); retryTemplate.setRetryPolicy(new SimpleRetryPolicy(3, Collections.<Class<? extends Throwable>, Boolean>singletonMap(RedisConnectionFailureException.class, true))); ExponentialBackOffPolicy backOffPolicy = new ExponentialBackOffPolicy(); backOffPolicy.setInitialInterval(1000L); backOffPolicy.setMaxInterval(1000L); backOffPolicy.setMultiplier(2); retryTemplate.setBackOffPolicy(backOffPolicy); return retryTemplate; }