Skip to content

Commit

Permalink
Extract testing enum for reuse
Browse files Browse the repository at this point in the history
  • Loading branch information
findepi committed Jan 18, 2022
1 parent 54419f2 commit adbc1fd
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 20 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* 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 io.trino.plugin.base.cache;

import org.testng.annotations.DataProvider;

import java.util.stream.Stream;

enum Invalidation
{
INVALIDATE_KEY,
INVALIDATE_PREDEFINED_KEYS,
INVALIDATE_SELECTED_KEYS,
INVALIDATE_ALL,
/**/;

@DataProvider
public static Object[][] invalidations()
{
return Stream.of(values())
.map(invalidation -> new Object[] {invalidation})
.toArray(Object[][]::new);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import com.google.common.cache.CacheBuilder;
import com.google.common.cache.CacheStats;
import io.airlift.concurrent.MoreFutures;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;

import java.util.List;
Expand All @@ -28,7 +27,6 @@
import java.util.concurrent.Future;
import java.util.concurrent.atomic.AtomicLong;
import java.util.stream.IntStream;
import java.util.stream.Stream;

import static com.google.common.collect.ImmutableList.toImmutableList;
import static com.google.common.collect.ImmutableSet.toImmutableSet;
Expand All @@ -43,14 +41,6 @@ public class TestEvictableCache
{
private static final int TEST_TIMEOUT_MILLIS = 10_000;

private enum Invalidation
{
INVALIDATE_KEY,
INVALIDATE_PREDEFINED_KEYS,
INVALIDATE_SELECTED_KEYS,
INVALIDATE_ALL,
}

@Test(timeOut = TEST_TIMEOUT_MILLIS)
public void testLoad()
throws Exception
Expand All @@ -67,7 +57,7 @@ public void testLoad()
/**
* Covers https://github.com/google/guava/issues/1881
*/
@Test(timeOut = TEST_TIMEOUT_MILLIS, dataProvider = "invalidations")
@Test(timeOut = TEST_TIMEOUT_MILLIS, dataProviderClass = Invalidation.class, dataProvider = "invalidations")
public void testInvalidateOngoingLoad(Invalidation invalidation)
throws Exception
{
Expand Down Expand Up @@ -126,7 +116,7 @@ public void testInvalidateOngoingLoad(Invalidation invalidation)
/**
* Covers https://github.com/google/guava/issues/1881
*/
@Test(invocationCount = 10, timeOut = TEST_TIMEOUT_MILLIS, dataProvider = "invalidations")
@Test(invocationCount = 10, timeOut = TEST_TIMEOUT_MILLIS, dataProviderClass = Invalidation.class, dataProvider = "invalidations")
public void testInvalidateAndLoadConcurrently(Invalidation invalidation)
throws Exception
{
Expand Down Expand Up @@ -190,12 +180,4 @@ public void testInvalidateAndLoadConcurrently(Invalidation invalidation)
executor.awaitTermination(10, SECONDS);
}
}

@DataProvider
public static Object[][] invalidations()
{
return Stream.of(Invalidation.values())
.map(invalidation -> new Object[] {invalidation})
.toArray(Object[][]::new);
}
}

0 comments on commit adbc1fd

Please sign in to comment.