<commit_before>/*
 * Copyright (C) 2015 <NAME>
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.bendb.thrifty.integration;

import com.bendb.thrifty.service.ServiceMethodCallback;

import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;

/**
 * A convenience class for testing Thrifty remote method calls.
 *
 * <p>Allows for blocking, checking results, timing out, and failing in a
 * test-friendly way with AssertionErrors.
 */
public class AssertingCallback<T> implements ServiceMethodCallback<T> {
    private T result;
    private Throwable error;

    private CountDownLatch latch = new CountDownLatch(1);

    @Override
    public void onSuccess(T result) {
        this.result = result;
        latch.countDown();
    }

    @Override
    public void onError(Throwable error) {
        this.error = error;
        latch.countDown();
    }

    public void await() {
        try {
            latch.await(2000, TimeUnit.MILLISECONDS);
        } catch (InterruptedException e) {
            throw new AssertionError("Client callback timed out after 2 seconds");
        }
    }

    public T getResult() throws Throwable {
        await();

        if (error != null) {
            throw error;
        }

        return result;
    }

    public Throwable getError() {
        return error;
    }
}<commit_msg>Fix CountdownLatch usage in AssertingCallback<commit_after>/*
 * Copyright (C) 2015 <NAME>
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.bendb.thrifty.integration;

import com.bendb.thrifty.service.ServiceMethodCallback;

import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;

/**
 * A convenience class for testing Thrifty remote method calls.
 *
 * <p>Allows for blocking, checking results, timing out, and failing in a
 * test-friendly way with AssertionErrors.
 */
public class AssertingCallback<T> implements ServiceMethodCallback<T> {
    private T result;
    private Throwable error;

    private CountDownLatch latch = new CountDownLatch(1);

    @Override
    public void onSuccess(T result) {
        this.result = result;
        latch.countDown();
    }

    @Override
    public void onError(Throwable error) {
        this.error = error;
        latch.countDown();
    }

    public T getResult() throws Throwable {
        await();

        if (error != null) {
            throw error;
        }

        return result;
    }

    public Throwable getError() {
        await();

        return error;
    }

    private void await() {
        try {
            if (!latch.await(2000, TimeUnit.MILLISECONDS)) {
                throw new AssertionError("Client callback timed out after 2 seconds");
            }

        } catch (InterruptedException e) {
            throw new AssertionError(e);
        }
    }
}
{'fraction_non_alphanumeric': 0.08528341133645345, 'fraction_numerical': 0.007280291211648466, 'mean_word_length': 2.7789783889980355, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '7594714', 'n_tokens_mistral': 1071, 'n_tokens_neox': 1033, 'n_words': 375}