<commit_before>/*
 * Copyright 2017 The Hekate Project
 *
 * The Hekate Project licenses this file to you 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 io.hekate.task.internal;

import io.hekate.HekateInstanceContextTestBase;
import io.hekate.HekateTestContext;
import io.hekate.cluster.ClusterNode;
import io.hekate.core.HekateTestInstance;
import io.hekate.core.internal.util.Utils;
import io.hekate.task.TaskServiceFactory;
import io.hekate.util.HekateFuture;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicReference;
import java.util.function.Consumer;
import org.junit.Before;

import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;

public abstract class TaskServiceTestBase extends HekateInstanceContextTestBase {
    protected static class NonSerializable {
        // No-op.
    }

    public static class NonSerializableTestException extends RuntimeException {
        private static final long serialVersionUID = 1L;

        private final NonSerializable nonSerializable = new NonSerializable();

        @Override
        public String toString() {
            return super.toString() + nonSerializable;
        }
    }

    protected static final AtomicInteger COUNTER = new AtomicInteger();

    protected static final List<ClusterNode> NODES = Collections.synchronizedList(new ArrayList<>());

    protected static final AtomicReference<HekateTestInstance> REF = new AtomicReference<>();

    public TaskServiceTestBase(HekateTestContext params) {
        super(params);
    }

    @Before
    @Override
    public void setUp() throws Exception {
        super.setUp();

        COUNTER.set(0);
        NODES.clear();
        REF.set(null);
    }

    protected void assertErrorCausedBy(HekateFuture future, Class<? extends Throwable> type) throws Exception {
        assertErrorCausedBy(future, type, null);
    }

    protected void assertErrorCausedBy(HekateFuture future, Class<? extends Throwable> type, Consumer<Throwable> check)
        throws Exception {
        doAssertErrorCausedBy(type, check, () -> get(future));
        doAssertErrorCausedBy(type, check, future::get);
        doAssertErrorCausedBy(type, check, future::getUninterruptedly);
    }

    protected List<HekateTestInstance> createAndJoin(int size) throws Exception {
        List<HekateTestInstance> nodes = new ArrayList<>(size);
<commit_msg>Fixed 'unchecked' warning.<commit_after>/*
 * Copyright 2017 The Hekate Project
 *
 * The Hekate Project licenses this file to you 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 io.hekate.task.internal;

import io.hekate.HekateInstanceContextTestBase;
import io.hekate.HekateTestContext;
import io.hekate.cluster.ClusterNode;
import io.hekate.core.HekateTestInstance;
import io.hekate.core.internal.util.Utils;
import io.hekate.task.TaskServiceFactory;
import io.hekate.util.HekateFuture;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicReference;
import java.util.function.Consumer;
import org.junit.Before;

import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;

public abstract class TaskServiceTestBase extends HekateInstanceContextTestBase {
    protected static class NonSerializable {
        // No-op.
    }

    public static class NonSerializableTestException extends RuntimeException {
        private static final long serialVersionUID = 1L;

        private final NonSerializable nonSerializable = new NonSerializable();

        @Override
        public String toString() {
            return super.toString() + nonSerializable;
        }
    }

    protected static final AtomicInteger COUNTER = new AtomicInteger();

    protected static final List<ClusterNode> NODES = Collections.synchronizedList(new ArrayList<>());

    protected static final AtomicReference<HekateTestInstance> REF = new AtomicReference<>();

    public TaskServiceTestBase(HekateTestContext params) {
        super(params);
    }

    @Before
    @Override
    public void setUp() throws Exception {
        super.setUp();

        COUNTER.set(0);
        NODES.clear();
        REF.set(null);
    }

    protected void assertErrorCausedBy(HekateFuture future, Class<? extends Throwable> type) throws Exception {
        assertErrorCausedBy(future, type, null);
    }

    protected void assertErrorCausedBy(HekateFuture<?, ?> future, Class<? extends Throwable> type, Consumer<Throwable> check)
        throws Exception {
        doAssertErrorCausedBy(type, check, () -> get(future));
        doAssertErrorCausedBy(type, check, future::get);
        doAssertErrorCausedBy(type, check, future::getUninterruptedly);
    }

    protected List<HekateTestInstance> createAndJoin(int size) throws Exception {
        List<HekateTestInstance> nodes = new ArrayList<>(size);

{'fraction_non_alphanumeric': 0.08483082402460741, 'fraction_numerical': 0.0032378177108628786, 'mean_word_length': 3.9862792574656982, 'pattern_counts': {'":': 0, '<': 24, '<?xml version=': 0, '>': 26, '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': '6963071', 'n_tokens_mistral': 1709, 'n_tokens_neox': 1650, 'n_words': 496}