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

Parallelized test execution #3057

Draft
wants to merge 7 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public class RangeSetTest {
@RegisterExtension
static final TestDatabaseExtension dbExtension = new TestDatabaseExtension();
@RegisterExtension
TestSubspaceExtension rsSubspaceExtension = new TestSubspaceExtension(dbExtension);
final TestSubspaceExtension rsSubspaceExtension = new TestSubspaceExtension(dbExtension);
private Database db;
private Subspace rsSubspace;
private RangeSet rs;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
* LimitConcurrencyExtension.java
*
* This source file is part of the FoundationDB open source project
*
* Copyright 2015-2024 Apple Inc. and the FoundationDB project authors
*
* 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.apple.test;

import com.google.auto.service.AutoService;
import org.junit.jupiter.api.Order;
import org.junit.jupiter.api.extension.AfterEachCallback;
import org.junit.jupiter.api.extension.BeforeEachCallback;
import org.junit.jupiter.api.extension.Extension;
import org.junit.jupiter.api.extension.ExtensionContext;

import javax.annotation.Nonnull;
import java.util.concurrent.Semaphore;

@AutoService(Extension.class)
@Order(0)
public class LimitConcurrencyExtension implements BeforeEachCallback, AfterEachCallback {
@Nonnull
static Semaphore testConcurrency = new Semaphore(Integer.parseInt(System.getProperty("com.apple.foundationdb.test.concurrencyLimit", "50")));

@Override
public void beforeEach(final ExtensionContext context) throws InterruptedException {
testConcurrency.acquire();
}

@Override
public void afterEach(final ExtensionContext context) {
testConcurrency.release();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Order;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;
Expand All @@ -60,8 +61,10 @@
public class ConcatCursorTest {

@RegisterExtension
@Order(0)
final FDBDatabaseExtension dbExtension = new FDBDatabaseExtension();
@RegisterExtension
@Order(1)
final TestKeySpacePathManagerExtension pathManager = new TestKeySpacePathManagerExtension(dbExtension);
FDBDatabase fdb;
FDBRecordContext context;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
package com.apple.foundationdb.record.provider.common;

import org.junit.jupiter.api.Test;

import javax.annotation.Nonnull;
import javax.crypto.Cipher;
import java.security.GeneralSecurityException;

Expand All @@ -40,37 +42,43 @@
public class MappedPoolTest {

public static String CIPHER = "DES/ECB/PKCS5Padding";
public static MappedPool<String, Cipher, GeneralSecurityException> MAPPED_POOL = new MappedPool<>(Cipher::getInstance);

@Nonnull
private MappedPool<String, Cipher, GeneralSecurityException> getPool() {
return new MappedPool<>(Cipher::getInstance);
}

@Test
public void testCipherPool() throws Exception {
final var mappedPool = getPool();
Cipher lastCipher = null;
for (int i = 0; i < 100; i++) {
Cipher cipher = MAPPED_POOL.poll(CIPHER);
Cipher cipher = mappedPool.poll(CIPHER);
if (lastCipher != null) {
assertSame(cipher, lastCipher);
lastCipher = cipher;
}
assertNotNull(cipher);
assertTrue(MAPPED_POOL.offer(CIPHER, cipher));
assertTrue(mappedPool.offer(CIPHER, cipher));
}
assertEquals(1, MAPPED_POOL.getPoolSize(CIPHER));
assertThat(MAPPED_POOL.getKeys(), hasItem(CIPHER));
assertEquals(1, mappedPool.getPoolSize(CIPHER));
assertThat(mappedPool.getKeys(), hasItem(CIPHER));
}

@Test
public void testMaxPoolSize() throws Exception {
final var mappedPool = getPool();
Cipher[] ciphers = new Cipher[1000];
for (int i = 0; i < 1000; i++) {
ciphers[i] = MAPPED_POOL.poll(CIPHER);
ciphers[i] = mappedPool.poll(CIPHER);
}
for (int i = 0; i < MappedPool.DEFAULT_POOL_SIZE; i++) {
assertTrue(MAPPED_POOL.offer(CIPHER, ciphers[i]));
assertTrue(mappedPool.offer(CIPHER, ciphers[i]));
}
for (int i = MappedPool.DEFAULT_POOL_SIZE; i < 1000; i++) {
assertFalse(MAPPED_POOL.offer(CIPHER, ciphers[i]));
assertFalse(mappedPool.offer(CIPHER, ciphers[i]));
}
assertEquals(64, MAPPED_POOL.getPoolSize(CIPHER));
assertEquals(64, mappedPool.getPoolSize(CIPHER));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;
import org.junit.jupiter.api.parallel.Isolated;

import java.util.concurrent.CompletableFuture;
import java.util.concurrent.TimeUnit;
Expand All @@ -36,6 +37,7 @@
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;

@Isolated
@Tag(Tags.RequiresFDB)
class BlockingInAsyncDetectionTest {
@RegisterExtension
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import com.google.protobuf.Message;
import org.apache.logging.log4j.ThreadContext;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Order;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;
Expand Down Expand Up @@ -70,8 +71,10 @@
@Tag(Tags.RequiresFDB)
public class FDBDatabaseRunnerTest {
@RegisterExtension
@Order(0)
final FDBDatabaseExtension dbExtension = new FDBDatabaseExtension();
@RegisterExtension
@Order(1)
final TestKeySpacePathManagerExtension pathManager = new TestKeySpacePathManagerExtension(dbExtension);

FDBDatabase database;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,15 @@
import com.apple.test.BooleanSource;
import com.apple.test.Tags;
import com.google.protobuf.Message;
import org.junit.jupiter.api.Order;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;
import org.junit.jupiter.api.function.Executable;
import org.junit.jupiter.api.parallel.Execution;
import org.junit.jupiter.api.parallel.ExecutionMode;
import org.junit.jupiter.api.parallel.ResourceLock;
import org.junit.jupiter.api.parallel.Resources;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.EnumSource;
import org.slf4j.Logger;
Expand Down Expand Up @@ -83,8 +86,10 @@ class FDBDatabaseTest {
@Nonnull
private static final Logger LOGGER = LoggerFactory.getLogger(FDBDatabaseTest.class);
@RegisterExtension
@Order(0)
final FDBDatabaseExtension dbExtension = new FDBDatabaseExtension();
@RegisterExtension
@Order(1)
final TestKeySpacePathManagerExtension pathManager = new TestKeySpacePathManagerExtension(dbExtension);

@Test
Expand Down Expand Up @@ -216,6 +221,7 @@ void cachedReadVersionWithRetryLoops(boolean async) throws InterruptedException,

@ParameterizedTest(name = "testJoinNowOnCompletedFuture (behavior = {0})")
@EnumSource(BlockingInAsyncDetection.class)
@ResourceLock(Resources.GLOBAL)
void testJoinNowOnCompletedFuture(BlockingInAsyncDetection behavior) {
FDBDatabaseFactory factory = dbExtension.getDatabaseFactory();
factory.setBlockingInAsyncDetection(behavior);
Expand All @@ -231,6 +237,7 @@ void testJoinNowOnCompletedFuture(BlockingInAsyncDetection behavior) {

@ParameterizedTest(name = "testJoinNowOnNonCompletedFuture (behavior = {0})")
@EnumSource(BlockingInAsyncDetection.class)
@ResourceLock(Resources.GLOBAL)
void testJoinNowOnNonCompletedFuture(BlockingInAsyncDetection behavior) {
FDBDatabaseFactory factory = dbExtension.getDatabaseFactory();
factory.setBlockingInAsyncDetection(behavior);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
import com.google.protobuf.Descriptors;
import com.google.protobuf.ExtensionRegistry;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Order;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;
Expand Down Expand Up @@ -103,8 +104,10 @@
@Tag(Tags.RequiresFDB)
public class FDBMetaDataStoreTest {
@RegisterExtension
@Order(0)
final FDBDatabaseExtension dbExtension = new FDBDatabaseExtension();
@RegisterExtension
@Order(1)
final TestKeySpacePathManagerExtension pathManager = new TestKeySpacePathManagerExtension(dbExtension);

FDBDatabase fdb;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,12 @@
import com.google.common.base.Utf8;
import com.google.common.collect.ImmutableList;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Order;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;
import org.junit.jupiter.api.parallel.ResourceLock;
import org.junit.jupiter.api.parallel.Resources;
import org.junit.jupiter.params.ParameterizedTest;

import javax.annotation.Nonnull;
Expand Down Expand Up @@ -82,8 +85,10 @@
@Tag(Tags.RequiresFDB)
public class FDBRecordContextTest {
@RegisterExtension
@Order(0)
final FDBDatabaseExtension dbExtension = new FDBDatabaseExtension();
@RegisterExtension
@Order(1)
final TestKeySpacePathManagerExtension pathManager = new TestKeySpacePathManagerExtension(dbExtension);

// A list of transaction IDs where the left item is the original ID and the right item is the expected
Expand Down Expand Up @@ -333,6 +338,7 @@ public void getReadVersionWithWeakReadSemantics() {
}
}

@ResourceLock(Resources.GLOBAL)
@Test
public void getReadVersionAtBatch() {
final FDBStoreTimer timer = new FDBStoreTimer();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import com.apple.test.Tags;
import com.google.common.collect.ImmutableMap;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Order;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.extension.RegisterExtension;
import org.slf4j.Logger;
Expand All @@ -57,8 +58,10 @@
@Tag(Tags.RequiresFDB)
public class FDBRecordStoreConcurrentTestBase {
@RegisterExtension
@Order(0)
protected final FDBDatabaseExtension dbExtension = new FDBDatabaseExtension();
@RegisterExtension
@Order(1)
protected final TestKeySpacePathManagerExtension pathManager = new TestKeySpacePathManagerExtension(dbExtension);

private static final Logger LOGGER = LoggerFactory.getLogger(FDBRecordStoreConcurrentTestBase.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@
import com.google.protobuf.Message;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.parallel.Execution;
import org.junit.jupiter.api.parallel.ExecutionMode;

import javax.annotation.Nonnull;
import java.util.HashMap;
Expand All @@ -69,6 +71,7 @@
* Tests related to built in functionality for getting the count of records in a store.
*/
@Tag(Tags.RequiresFDB)
@Execution(ExecutionMode.CONCURRENT)
public class FDBRecordStoreCountRecordsTest extends FDBRecordStoreTestBase {

@Test
Expand Down Expand Up @@ -380,7 +383,7 @@ public void addCountIndex() throws Exception {
}

// Build the index
try (OnlineIndexer onlineIndexBuilder = OnlineIndexer.forRecordStoreAndIndex(recordStore, "record_count")) {
try (OnlineIndexer onlineIndexBuilder = newIndexer("record_count")) {
onlineIndexBuilder.buildIndex();
}
try (FDBRecordContext context = openContext()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1239,8 +1239,7 @@ void markReadableTest() throws Exception {
openSimpleRecordStore(context);
Index index = recordStore.getRecordMetaData().getIndex(indexName);
assertThat(recordStore.isIndexReadable(index), is(false));
try (OnlineIndexer indexBuilder = OnlineIndexer.newBuilder().setRecordStore(recordStore).setIndex(index)
.build()) {
try (OnlineIndexer indexBuilder = newIndexer(indexName)) {
indexBuilder.buildIndex(false);
}
commit(context);
Expand Down Expand Up @@ -2251,7 +2250,7 @@ public IndexState needRebuildIndex(Index index, long recordCount, boolean indexO
recordStore.clearAndMarkIndexWriteOnly("index-1").join();
context.commit();
}
try (OnlineIndexer onlineIndexBuilder = OnlineIndexer.forRecordStoreAndIndex(recordStore, "index-1")) {
try (OnlineIndexer onlineIndexBuilder = newIndexerBuilder().setIndex("index-1").build()) {
onlineIndexBuilder.buildIndex();
}
try (FDBRecordContext context = openContext()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -305,4 +305,18 @@ protected FDBStoredRecord<Message> saveAndSplitSimpleRecord(long recno, String s
md.removeIndex("MySimpleRecord$str_value_indexed");
md.setStoreRecordVersions(false);
};

@Nonnull
protected OnlineIndexer.Builder newIndexerBuilder() {
return OnlineIndexer.newBuilder()
.setRecordStore(recordStore)
.setPriority(FDBTransactionPriority.DEFAULT);
}

@Nonnull
protected OnlineIndexer newIndexer(@Nonnull String indexName) {
return newIndexerBuilder()
.setIndex(indexName)
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@
import com.apple.foundationdb.record.metadata.Key;
import com.apple.foundationdb.record.provider.foundationdb.indexes.InvalidIndexEntry;
import com.apple.foundationdb.record.provider.foundationdb.indexes.ValueIndexMaintainer;
import com.apple.foundationdb.record.query.QueryToKeyMatcher;
import com.apple.foundationdb.record.provider.foundationdb.keyspace.KeySpacePath;
import com.apple.foundationdb.record.query.QueryToKeyMatcher;
import com.apple.foundationdb.record.query.plan.QueryPlanner;
import com.apple.foundationdb.record.test.TestKeySpace;
import com.apple.foundationdb.record.util.pair.Pair;
Expand All @@ -59,6 +59,8 @@
import org.hamcrest.Matchers;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.parallel.Execution;
import org.junit.jupiter.api.parallel.ExecutionMode;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;
Expand Down Expand Up @@ -98,6 +100,7 @@
* Tests of uniqueness checks.
*/
@Tag(Tags.RequiresFDB)
@Execution(ExecutionMode.CONCURRENT)
public class FDBRecordStoreUniqueIndexTest extends FDBRecordStoreTestBase {

private static final String NO_UNIQUE_CLEAR_INDEX_TYPE = "no_unique_clear";
Expand Down Expand Up @@ -310,8 +313,7 @@ void multipleStores() throws Exception {
recordStore = createOrOpenRecordStore(context, simpleMetaData(uniqueHook), path).getLeft();
commit(context);

try (OnlineIndexer indexBuilder = OnlineIndexer.newBuilder()
.setRecordStore(recordStore)
try (OnlineIndexer indexBuilder = newIndexerBuilder()
.setTargetIndexes(List.of(uniqueIndex))
.setIndexingPolicy(OnlineIndexer.IndexingPolicy.newBuilder()
.allowUniquePendingState(true))
Expand Down Expand Up @@ -630,8 +632,7 @@ public void addUniqueIndexViaBuild() {
if (allowReadableUniquePending) {
indexingPolicy.allowUniquePendingState();
}
try (OnlineIndexer indexer = OnlineIndexer.newBuilder()
.setRecordStore(recordStore)
try (OnlineIndexer indexer = newIndexerBuilder()
.setTargetIndexesByName(List.of(uniqueIndex.getName()))
.setIndexingPolicy(indexingPolicy
.build()).build()) {
Expand Down
Loading