<commit_before>package com.pushtorefresh.storio.test;

import android.support.annotation.NonNull;

import java.util.Queue;
import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.concurrent.atomic.AtomicBoolean;

import rx.Subscription;

public abstract class AbstractEmissionChecker<T> {

    @NonNull
    private final Queue<T> expectedValues;

    @NonNull
    private final AtomicBoolean expectedValueReceived = new AtomicBoolean(false);

    public AbstractEmissionChecker(@NonNull Queue<T> expectedValues) {
        this.expectedValues = new ConcurrentLinkedQueue<T>(expectedValues);
    }

    /**
     * Returns timeout of assertion for {@link #assertThatNextExpectedValueReceived()}.
     *
     * @return timeout in millis.
     */
    protected long timeoutMillis() {
        return 15000; // 15 seconds
    }

    /**
     * Asserts that next expected value was received.
     */
    public void assertThatNextExpectedValueReceived() {
        final long startTime = System.currentTimeMillis(); // We can not use SystemClock here :( Not in class path
        final long timeoutMillis = timeoutMillis();

        while (!expectedValueReceived.get()
                && !(System.currentTimeMillis() - startTime > timeoutMillis)) {
            Thread.yield();
        }

        if (!expectedValueReceived.get()) {
            throw new AssertionError("Expected value = " + expectedValues.peek() + " was not received, " +
                    "timeout = " + timeoutMillis + "ms, expectedValues.size = " + expectedValues.size());
        } else {
            // reset flag
            expectedValueReceived.set(false);
        }
    }

    /**
     * Asserts that all expected values were received.
     */
    public void assertThatNoExpectedValuesLeft() {
        if (expectedValues.size() != 0) {
            throw new AssertionError("Not all expected values were received: queue = " + expectedValues);
        }
    }

    /**
     * Checks that new received value is expected.
     *
     * @param obtained new value.
     */
    protected void onNextObtained(@NonNull T obtained) {
        final T expectedItem = expectedValues.remove();

        if (!expectedItem.equals(obtained)) {
            throw new AssertionError("Obtained item not equals to expected: obtained = "
                    + obtained + ", expected = " + expectedItem);
        }

        if (expectedValueReceived.get()) {
            throw new AssertionError("Incorrect state");
        }

        expectedValueReceived.set(true);
    }

    // TODO: Refactor, probably better to provide Observable itself.
    @NonNull
    public abstract Subscription subscribe();
}<commit_msg>Increase timeout for emission checker<commit_after>package com.pushtorefresh.storio.test;

import android.support.annotation.NonNull;

import java.util.Queue;
import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.concurrent.atomic.AtomicBoolean;

import rx.Subscription;

public abstract class AbstractEmissionChecker<T> {

    @NonNull
    private final Queue<T> expectedValues;

    @NonNull
    private final AtomicBoolean expectedValueReceived = new AtomicBoolean(false);

    public AbstractEmissionChecker(@NonNull Queue<T> expectedValues) {
        this.expectedValues = new ConcurrentLinkedQueue<T>(expectedValues);
    }

    /**
     * Returns timeout of assertion for {@link #assertThatNextExpectedValueReceived()}.
     *
     * @return timeout in millis.
     */
    protected long timeoutMillis() {
        return 60000; // 60 seconds
    }

    /**
     * Asserts that next expected value was received.
     */
    public void assertThatNextExpectedValueReceived() {
        final long startTime = System.currentTimeMillis(); // We can not use SystemClock here :( Not in class path
        final long timeoutMillis = timeoutMillis();

        while (!expectedValueReceived.get()
                && !(System.currentTimeMillis() - startTime > timeoutMillis)) {
            Thread.yield();
        }

        if (!expectedValueReceived.get()) {
            throw new AssertionError("Expected value = " + expectedValues.peek() + " was not received, " +
                    "timeout = " + timeoutMillis + "ms, expectedValues.size = " + expectedValues.size());
        } else {
            // reset flag
            expectedValueReceived.set(false);
        }
    }

    /**
     * Asserts that all expected values were received.
     */
    public void assertThatNoExpectedValuesLeft() {
        if (expectedValues.size() != 0) {
            throw new AssertionError("Not all expected values were received: queue = " + expectedValues);
        }
    }

    /**
     * Checks that new received value is expected.
     *
     * @param obtained new value.
     */
    protected void onNextObtained(@NonNull T obtained) {
        final T expectedItem = expectedValues.remove();

        if (!expectedItem.equals(obtained)) {
            throw new AssertionError("Obtained item not equals to expected: obtained = "
                    + obtained + ", expected = " + expectedItem);
        }

        if (expectedValueReceived.get()) {
            throw new AssertionError("Incorrect state");
        }

        expectedValueReceived.set(true);
    }

    // TODO: Refactor, probably better to provide Observable itself.
    @NonNull
    public abstract Subscription subscribe();
}

{'fraction_non_alphanumeric': 0.09786046511627906, 'fraction_numerical': 0.0029767441860465114, 'mean_word_length': 2.5555555555555554, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 13, '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': '538744', 'n_tokens_mistral': 1383, 'n_tokens_neox': 1358, 'n_words': 370}