<commit_before>package com.solambda.swiffer.api.internal.decisions;

import static com.solambda.swiffer.test.Tests.failWith;
import static com.solambda.swiffer.test.Tests.returnAfterDelay;
import static com.solambda.swiffer.test.Tests.sleep;
import static java.time.Duration.ofMillis;
import static java.util.concurrent.TimeUnit.MILLISECONDS;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
import static org.assertj.core.api.Assertions.fail;
import static org.mockito.Matchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

import java.time.Duration;
import java.util.concurrent.CancellationException;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;

import org.assertj.core.data.Offset;
import org.junit.Test;

import com.amazonaws.services.simpleworkflow.AmazonSimpleWorkflow;
import com.amazonaws.services.simpleworkflow.model.DecisionTask;
import com.google.common.base.Stopwatch;
import com.solambda.swiffer.api.exceptions.TaskContextPollingException;

public class DecisionTaskContextPollerTest {

	private static final String TOKEN = "token";

	@Test
	public void polling_shouldReturnADecisionTaskContext() throws Exception {
		// GIVEN
		final AmazonSimpleWorkflow swf = mock(AmazonSimpleWorkflow.class);
		final DecisionTask task = new DecisionTask().withTaskToken(TOKEN);
		when(swf.pollForDecisionTask(any())).thenReturn(task);
		final DecisionTaskPoller poller = new DecisionTaskPoller(swf, "domain", "DecisionTaskList", "decisionpoller");
		// WHEN start polling
		final DecisionTaskContext taskContext = poller.poll();
		// THEN
		assertThat(taskContext.taskToken()).isEqualTo(TOKEN);
	}

	@Test
	public void pollingFailure_throwsAnException() throws Exception {
		// GIVEN
		final AmazonSimpleWorkflow swf = mock(AmazonSimpleWorkflow.class);
		final String expectedMessage = "exception for testing";
		when(swf.pollForDecisionTask(any())).then(failWith(new Exception(expectedMessage)));
		final DecisionTaskPoller poller = new DecisionTaskPoller(swf, "domain", "DecisionTaskList", "activit");
		// WHEN start polling THEN correct exception is thrown
		assertThatExceptionOfType(TaskContextPollingException.class)
				.isThrownBy(() -> poller.poll())
				.withRootCauseExactlyInstanceOf(Exception.class)
				.withStackTraceContaining(expectedMessage);

	}

	@Test
	public void polling_isABlockingOperation() throws Exception {
		// GIVEN a blocking polling operation
		final AmazonSimpleWorkflow swf = mock(AmazonSimpleWorkflow.class);
		final DecisionTask task = new DecisionTask().withTaskToken(TOKEN);
		final int expectedPollingDuration = 500;
		when(swf.pollForDecisionTask(any()))
				.then(returnAfterDelay(task, Duration.ofMillis(expectedPollingDuration)));
		final DecisionTaskPoller poller = new DecisionTaskPoller(swf, "domain", "DecisionTaskList", "decisionpoller");
		// WHEN start polling
		final Stopwatch watch = Stopwatch.createStarted();
		final Future<DecisionTaskContext> pollingFuture = Executors.newSingleThreadExecutor()
				.submit(() -> poller.poll());
		final DecisionTaskContext context = pollingFuture.get(expectedPollingDuration + 100, MILLISECONDS);
		// THEN the polling operation blocked
		assertThat(watch.elapsed(MILLISECONDS)).isCloseTo(expectedPollingDuration, Offset.offset(80L));
		assertThat(context.taskToken()).isEqualTo(TOKEN);
	}<commit_msg>[travis] increase assertion comparison offset<commit_after>package com.solambda.swiffer.api.internal.decisions;

import static com.solambda.swiffer.test.Tests.failWith;
import static com.solambda.swiffer.test.Tests.returnAfterDelay;
import static com.solambda.swiffer.test.Tests.sleep;
import static java.time.Duration.ofMillis;
import static java.util.concurrent.TimeUnit.MILLISECONDS;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
import static org.assertj.core.api.Assertions.fail;
import static org.mockito.Matchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

import java.time.Duration;
import java.util.concurrent.CancellationException;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;

import org.assertj.core.data.Offset;
import org.junit.Test;

import com.amazonaws.services.simpleworkflow.AmazonSimpleWorkflow;
import com.amazonaws.services.simpleworkflow.model.DecisionTask;
import com.google.common.base.Stopwatch;
import com.solambda.swiffer.api.exceptions.TaskContextPollingException;

public class DecisionTaskContextPollerTest {

	private static final String TOKEN = "token";

	@Test
	public void polling_shouldReturnADecisionTaskContext() throws Exception {
		// GIVEN
		final AmazonSimpleWorkflow swf = mock(AmazonSimpleWorkflow.class);
		final DecisionTask task = new DecisionTask().withTaskToken(TOKEN);
		when(swf.pollForDecisionTask(any())).thenReturn(task);
		final DecisionTaskPoller poller = new DecisionTaskPoller(swf, "domain", "DecisionTaskList", "decisionpoller");
		// WHEN start polling
		final DecisionTaskContext taskContext = poller.poll();
		// THEN
		assertThat(taskContext.taskToken()).isEqualTo(TOKEN);
	}

	@Test
	public void pollingFailure_throwsAnException() throws Exception {
		// GIVEN
		final AmazonSimpleWorkflow swf = mock(AmazonSimpleWorkflow.class);
		final String expectedMessage = "exception for testing";
		when(swf.pollForDecisionTask(any())).then(failWith(new Exception(expectedMessage)));
		final DecisionTaskPoller poller = new DecisionTaskPoller(swf, "domain", "DecisionTaskList", "activit");
		// WHEN start polling THEN correct exception is thrown
		assertThatExceptionOfType(TaskContextPollingException.class)
				.isThrownBy(() -> poller.poll())
				.withRootCauseExactlyInstanceOf(Exception.class)
				.withStackTraceContaining(expectedMessage);

	}

	@Test
	public void polling_isABlockingOperation() throws Exception {
		// GIVEN a blocking polling operation
		final AmazonSimpleWorkflow swf = mock(AmazonSimpleWorkflow.class);
		final DecisionTask task = new DecisionTask().withTaskToken(TOKEN);
		final int expectedPollingDuration = 500;
		when(swf.pollForDecisionTask(any()))
				.then(returnAfterDelay(task, Duration.ofMillis(expectedPollingDuration)));
		final DecisionTaskPoller poller = new DecisionTaskPoller(swf, "domain", "DecisionTaskList", "decisionpoller");
		// WHEN start polling
		final Stopwatch watch = Stopwatch.createStarted();
		final Future<DecisionTaskContext> pollingFuture = Executors.newSingleThreadExecutor()
				.submit(() -> poller.poll());
		final DecisionTaskContext context = pollingFuture.get(expectedPollingDuration + 400, MILLISECONDS);
		// THEN the polling operation blocked
		assertThat(watch.elapsed(MILLISECONDS)).isCloseTo(expectedPollingDuration, Offset.offset(80L));
		assertThat(context.taskToken()).isEqualTo(TOKEN);
	}
{'fraction_non_alphanumeric': 0.10094549499443826, 'fraction_numerical': 0.002224694104560623, 'mean_word_length': 6.4538860103626945, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3442433', 'n_tokens_mistral': 2271, 'n_tokens_neox': 2068, 'n_words': 416}