Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test param refactoring #259

Open
wants to merge 2 commits into
base: ignite-13772
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
package org.apache.ignite.internal.processors.query.calcite.exec.rel;

import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Deque;
import java.util.HashMap;
import java.util.List;
Expand All @@ -31,6 +30,8 @@
import java.util.concurrent.locks.LockSupport;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
import java.util.stream.Stream;

import com.google.common.collect.ImmutableMap;
import org.apache.ignite.internal.GridKernalContext;
import org.apache.ignite.internal.processors.query.calcite.exec.ArrayRowHandler;
Expand Down Expand Up @@ -82,20 +83,48 @@ public class AbstractExecutionTest extends GridCommonAbstractTest {
protected int nodesCnt = 3;

/** */
@Parameterized.Parameters(name = "Execution direction = {0}")
public static List<Object[]> parameters() {
ArrayList<Object[]> params = new ArrayList<>();
enum ExecutionStrategy {
/** */
FIFO {
@Override public T2<Runnable, Integer> nextTask(Deque<T2<Runnable, Integer>> tasks) {
return tasks.pollFirst();
}
},

params.add(new Object[]{true});
params.add(new Object[]{false});
params.add(new Object[]{null});
/** */
LIFO {
@Override public T2<Runnable, Integer> nextTask(Deque<T2<Runnable, Integer>> tasks) {
return tasks.pollLast();
}
},

return params;
/** */
RANDOM {
@Override public T2<Runnable, Integer> nextTask(Deque<T2<Runnable, Integer>> tasks) {
return ThreadLocalRandom.current().nextBoolean() ? tasks.pollLast() : tasks.pollFirst();
}
};

/**
* Returns a next task according to the strategy.
*
* @param tasks Task list.
* @return Next task.
*/
public T2<Runnable, Integer> nextTask(Deque<T2<Runnable, Integer>> tasks) {
throw new UnsupportedOperationException();
}
}

/** */
@Parameterized.Parameters(name = "Execution strategy = {0}")
public static List<Object[]> parameters() {
return Stream.of(ExecutionStrategy.values()).map(s -> new Object[]{s}).collect(Collectors.toList());
}

/** Execution direction. */
@Parameterized.Parameter
public static Boolean execDir;
public static ExecutionStrategy execStgy;

/** */
@Before
Expand Down Expand Up @@ -161,8 +190,7 @@ public IgniteTestStripedThreadPoolExecutor(int concurrentLvl, String igniteInsta
while (!stop.get()) {
synchronized (tasks) {
while (!tasks.isEmpty()) {
T2<Runnable, Integer> r = execDir != null ? (execDir ? tasks.pollLast() : tasks.pollFirst()) :
ThreadLocalRandom.current().nextBoolean() ? tasks.pollLast() : tasks.pollFirst();
T2<Runnable, Integer> r = execStgy.nextTask(tasks);

exec.execute(() -> super.execute(r.getKey(), r.getValue()));
}
Expand Down