Package com.linkedin.venice.utils
Class TestUtils
- java.lang.Object
-
- com.linkedin.venice.utils.TestUtils
-
public class TestUtils extends java.lang.Object
General-purpose utility functions for tests.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interface
TestUtils.NonDeterministicAssertion
-
Constructor Summary
Constructors Constructor Description TestUtils()
-
Method Summary
All Methods Static Methods Concrete Methods Deprecated Methods Modifier and Type Method Description static <T extends ControllerResponse>
TassertCommand(T response)
static <T extends ControllerResponse>
TassertCommand(T response, java.lang.String assertionErrorMessage)
static void
checkMissingFieldInAvroRecord(org.apache.avro.generic.GenericRecord record, java.lang.String fieldName)
static void
createAndVerifyStoreInAllRegions(java.lang.String storeName, ControllerClient parentControllerClient, java.util.List<ControllerClient> controllerClientList)
static Store
createTestStore(java.lang.String name, java.lang.String owner, long createdTime)
static VersionCreationResponse
createVersionWithBatchData(ControllerClient controllerClient, java.lang.String storeName, java.lang.String keySchema, java.lang.String valueSchema, java.util.stream.Stream<java.util.Map.Entry> batchData, int valueSchemaId, PubSubProducerAdapterFactory pubSubProducerAdapterFactory, java.util.Map<java.lang.String,java.lang.String> additionalProperties)
static VersionCreationResponse
createVersionWithBatchData(ControllerClient controllerClient, java.lang.String storeName, java.lang.String keySchema, java.lang.String valueSchema, java.util.stream.Stream<java.util.Map.Entry> batchData, PubSubProducerAdapterFactory pubSubProducerAdapterFactory, java.util.Map<java.lang.String,java.lang.String> additionalProperties)
static void
deleteDirectory(java.io.File fileToDelete)
static java.lang.String
dequalifyClassName(java.lang.String className)
static boolean
directoryContainsFolder(java.lang.String directoryPath, java.lang.String folderName)
static java.util.List<java.lang.String>
findFoldersWithFileExtension(java.io.File directory, java.lang.String fileExtension)
static java.util.Map<byte[],byte[]>
generateInput(int recordCnt, boolean sorted, int startId, AvroSerializer serializer)
static java.lang.String
getClusterToD2String(java.util.Map<java.lang.String,java.lang.String> clusterToD2)
static int
getFreePort()
WARNING: The code which generates the free port and uses it must always be called within a try/catch and a loop.static java.util.Map<java.lang.String,java.lang.Object>
getIngestionIsolationPropertyMap()
static VeniceControllerMultiClusterConfig
getMultiClusterConfigFromOneCluster(VeniceControllerClusterConfig controllerConfig)
static OffsetRecord
getOffsetRecord(long currentOffset)
static OffsetRecord
getOffsetRecord(long currentOffset, boolean complete)
static OffsetRecord
getOffsetRecord(long currentOffset, java.util.Optional<java.lang.Long> endOfPushOffset)
static SafeHelixManager
getParticipant(java.lang.String cluster, java.lang.String nodeId, java.lang.String zkAddress, int httpPort, java.lang.String stateModelDef)
Deprecated.TODO: migrate to use ServiceFactory for generating a participantstatic SafeHelixManager
getParticipant(java.lang.String cluster, java.lang.String nodeId, java.lang.String zkAddress, int httpPort, org.apache.helix.participant.statemachine.StateModelFactory<org.apache.helix.participant.statemachine.StateModel> stateModelFactory, java.lang.String stateModelDef)
static java.util.Properties
getPropertiesForControllerConfig()
static Store
getRandomStore()
static StoreIngestionTaskFactory.Builder
getStoreIngestionTaskBuilder(java.lang.String storeName)
static java.lang.String
getUniqueTopicString(java.lang.String prefix)
static VeniceWriterFactory
getVeniceWriterFactory(java.util.Properties properties, PubSubProducerAdapterFactory pubSubProducerAdapterFactory)
static java.lang.String
loadFileAsString(java.lang.String fileName)
static java.util.Map<java.lang.String,java.lang.String>
mergeConfigs(java.util.List<java.util.Map<java.lang.String,java.lang.String>> configMaps)
static void
preventSystemExit()
static void
restoreSystemExit()
static java.util.List<java.lang.String>
searchForFileExtension(java.io.File directory, java.lang.String fileExtension)
static void
shutdownExecutor(java.util.concurrent.ExecutorService executor)
static void
shutdownExecutor(java.util.concurrent.ExecutorService executor, long timeout, java.util.concurrent.TimeUnit unit)
static void
shutdownThread(java.lang.Thread thread)
static void
shutdownThread(java.lang.Thread thread, long timeout, java.util.concurrent.TimeUnit unit)
static ControllerResponse
updateStoreToHybrid(java.lang.String storeName, ControllerClient parentControllerClient, java.util.Optional<java.lang.Boolean> enableNativeReplication, java.util.Optional<java.lang.Boolean> enableActiveActiveReplication, java.util.Optional<java.lang.Boolean> enableChunking)
static void
verifyDCConfigNativeAndActiveRepl(java.lang.String storeName, boolean enabledNR, boolean enabledAA, ControllerClient... controllerClients)
static void
waitForNonDeterministicAssertion(long timeout, java.util.concurrent.TimeUnit timeoutUnit, boolean exponentialBackOff, boolean retryOnThrowable, TestUtils.NonDeterministicAssertion assertion)
static void
waitForNonDeterministicAssertion(long timeout, java.util.concurrent.TimeUnit timeoutUnit, boolean exponentialBackOff, TestUtils.NonDeterministicAssertion assertion)
static void
waitForNonDeterministicAssertion(long timeout, java.util.concurrent.TimeUnit timeoutUnit, TestUtils.NonDeterministicAssertion assertion)
To be used for tests when we need to wait for an async operation to complete.static void
waitForNonDeterministicCompletion(long timeout, java.util.concurrent.TimeUnit timeoutUnit, java.util.function.BooleanSupplier condition)
To be used for tests when we need to wait for an async operation to complete.static void
waitForNonDeterministicPushCompletion(java.lang.String topicName, ControllerClient controllerClient, long timeout, java.util.concurrent.TimeUnit timeoutUnit)
Wait for the push job for a store version or topic to be completed.static void
writeBatchData(VersionCreationResponse response, java.lang.String keySchema, java.lang.String valueSchema, java.util.stream.Stream<java.util.Map.Entry> batchData, int valueSchemaId, CompressionStrategy compressionStrategy, java.util.function.Function<java.lang.String,java.nio.ByteBuffer> compressionDictionaryGenerator, PubSubProducerAdapterFactory pubSubProducerAdapterFactory, java.util.Map<java.lang.String,java.lang.String> additionalProperties)
static void
writeBatchData(VersionCreationResponse response, java.lang.String keySchema, java.lang.String valueSchema, java.util.stream.Stream<java.util.Map.Entry> batchData, int valueSchemaId, PubSubProducerAdapterFactory pubSubProducerAdapterFactory, java.util.Map<java.lang.String,java.lang.String> additionalProperties)
-
-
-
Method Detail
-
dequalifyClassName
public static java.lang.String dequalifyClassName(java.lang.String className)
-
waitForNonDeterministicCompletion
public static void waitForNonDeterministicCompletion(long timeout, java.util.concurrent.TimeUnit timeoutUnit, java.util.function.BooleanSupplier condition) throws java.lang.AssertionError
To be used for tests when we need to wait for an async operation to complete. Pass a timeout, and a lambda for checking if the operation is complete.- Parameters:
timeout
- amount of time to waittimeoutUnit
-TimeUnit
for the {@param timeout}condition
- ABooleanSupplier
which should execute the non-deterministic action and return true if it is successful, false otherwise.- Throws:
java.lang.AssertionError
-
updateStoreToHybrid
public static ControllerResponse updateStoreToHybrid(java.lang.String storeName, ControllerClient parentControllerClient, java.util.Optional<java.lang.Boolean> enableNativeReplication, java.util.Optional<java.lang.Boolean> enableActiveActiveReplication, java.util.Optional<java.lang.Boolean> enableChunking)
-
waitForNonDeterministicAssertion
public static void waitForNonDeterministicAssertion(long timeout, java.util.concurrent.TimeUnit timeoutUnit, TestUtils.NonDeterministicAssertion assertion) throws java.lang.AssertionError
To be used for tests when we need to wait for an async operation to complete. Pass a timeout, and a labmda for checking if the operation is complete. There is an issue within Mockito where it emits VerifyError instead of ArgumentsAreDifferent Exception. Check out "ExceptionFactory#JunitArgsAreDifferent" for details. The workaround here is to catch both assert and verify error. TODO: find a better way resolve it- Parameters:
timeout
- amount of time to waittimeoutUnit
-TimeUnit
for the {@param timeout}assertion
- ATestUtils.NonDeterministicAssertion
which should simply execute without exception if it is successful, or throw anAssertionError
otherwise.- Throws:
java.lang.AssertionError
- throws the exception thrown by theTestUtils.NonDeterministicAssertion
if the maximum wait time has been exceeded.
-
waitForNonDeterministicAssertion
public static void waitForNonDeterministicAssertion(long timeout, java.util.concurrent.TimeUnit timeoutUnit, boolean exponentialBackOff, TestUtils.NonDeterministicAssertion assertion) throws java.lang.AssertionError
- Throws:
java.lang.AssertionError
-
waitForNonDeterministicAssertion
public static void waitForNonDeterministicAssertion(long timeout, java.util.concurrent.TimeUnit timeoutUnit, boolean exponentialBackOff, boolean retryOnThrowable, TestUtils.NonDeterministicAssertion assertion) throws java.lang.AssertionError
- Throws:
java.lang.AssertionError
-
createVersionWithBatchData
public static VersionCreationResponse createVersionWithBatchData(ControllerClient controllerClient, java.lang.String storeName, java.lang.String keySchema, java.lang.String valueSchema, java.util.stream.Stream<java.util.Map.Entry> batchData, PubSubProducerAdapterFactory pubSubProducerAdapterFactory, java.util.Map<java.lang.String,java.lang.String> additionalProperties)
-
createVersionWithBatchData
public static VersionCreationResponse createVersionWithBatchData(ControllerClient controllerClient, java.lang.String storeName, java.lang.String keySchema, java.lang.String valueSchema, java.util.stream.Stream<java.util.Map.Entry> batchData, int valueSchemaId, PubSubProducerAdapterFactory pubSubProducerAdapterFactory, java.util.Map<java.lang.String,java.lang.String> additionalProperties)
-
writeBatchData
public static void writeBatchData(VersionCreationResponse response, java.lang.String keySchema, java.lang.String valueSchema, java.util.stream.Stream<java.util.Map.Entry> batchData, int valueSchemaId, PubSubProducerAdapterFactory pubSubProducerAdapterFactory, java.util.Map<java.lang.String,java.lang.String> additionalProperties)
-
writeBatchData
public static void writeBatchData(VersionCreationResponse response, java.lang.String keySchema, java.lang.String valueSchema, java.util.stream.Stream<java.util.Map.Entry> batchData, int valueSchemaId, CompressionStrategy compressionStrategy, java.util.function.Function<java.lang.String,java.nio.ByteBuffer> compressionDictionaryGenerator, PubSubProducerAdapterFactory pubSubProducerAdapterFactory, java.util.Map<java.lang.String,java.lang.String> additionalProperties)
-
waitForNonDeterministicPushCompletion
public static void waitForNonDeterministicPushCompletion(java.lang.String topicName, ControllerClient controllerClient, long timeout, java.util.concurrent.TimeUnit timeoutUnit)
Wait for the push job for a store version or topic to be completed. The polling will fast fail if the push is found to be in ERROR state.
-
createTestStore
public static Store createTestStore(java.lang.String name, java.lang.String owner, long createdTime)
-
getParticipant
@Deprecated public static SafeHelixManager getParticipant(java.lang.String cluster, java.lang.String nodeId, java.lang.String zkAddress, int httpPort, java.lang.String stateModelDef)
Deprecated.TODO: migrate to use ServiceFactory for generating a participant
-
getParticipant
public static SafeHelixManager getParticipant(java.lang.String cluster, java.lang.String nodeId, java.lang.String zkAddress, int httpPort, org.apache.helix.participant.statemachine.StateModelFactory<org.apache.helix.participant.statemachine.StateModel> stateModelFactory, java.lang.String stateModelDef)
-
getOffsetRecord
public static OffsetRecord getOffsetRecord(long currentOffset)
-
getOffsetRecord
public static OffsetRecord getOffsetRecord(long currentOffset, boolean complete)
-
getOffsetRecord
public static OffsetRecord getOffsetRecord(long currentOffset, java.util.Optional<java.lang.Long> endOfPushOffset)
-
getMultiClusterConfigFromOneCluster
public static VeniceControllerMultiClusterConfig getMultiClusterConfigFromOneCluster(VeniceControllerClusterConfig controllerConfig)
-
getPropertiesForControllerConfig
public static java.util.Properties getPropertiesForControllerConfig()
-
getClusterToD2String
public static java.lang.String getClusterToD2String(java.util.Map<java.lang.String,java.lang.String> clusterToD2)
-
getVeniceWriterFactory
public static VeniceWriterFactory getVeniceWriterFactory(java.util.Properties properties, PubSubProducerAdapterFactory pubSubProducerAdapterFactory)
-
getRandomStore
public static Store getRandomStore()
-
assertCommand
public static <T extends ControllerResponse> T assertCommand(T response)
-
assertCommand
public static <T extends ControllerResponse> T assertCommand(T response, java.lang.String assertionErrorMessage)
-
preventSystemExit
public static void preventSystemExit()
-
restoreSystemExit
public static void restoreSystemExit()
-
createAndVerifyStoreInAllRegions
public static void createAndVerifyStoreInAllRegions(java.lang.String storeName, ControllerClient parentControllerClient, java.util.List<ControllerClient> controllerClientList)
-
verifyDCConfigNativeAndActiveRepl
public static void verifyDCConfigNativeAndActiveRepl(java.lang.String storeName, boolean enabledNR, boolean enabledAA, ControllerClient... controllerClients)
-
getStoreIngestionTaskBuilder
public static StoreIngestionTaskFactory.Builder getStoreIngestionTaskBuilder(java.lang.String storeName)
-
generateInput
public static java.util.Map<byte[],byte[]> generateInput(int recordCnt, boolean sorted, int startId, AvroSerializer serializer)
-
shutdownThread
public static void shutdownThread(java.lang.Thread thread) throws java.lang.InterruptedException
- Throws:
java.lang.InterruptedException
-
shutdownThread
public static void shutdownThread(java.lang.Thread thread, long timeout, java.util.concurrent.TimeUnit unit) throws java.lang.InterruptedException
- Throws:
java.lang.InterruptedException
-
shutdownExecutor
public static void shutdownExecutor(java.util.concurrent.ExecutorService executor) throws java.lang.InterruptedException
- Throws:
java.lang.InterruptedException
-
shutdownExecutor
public static void shutdownExecutor(java.util.concurrent.ExecutorService executor, long timeout, java.util.concurrent.TimeUnit unit) throws java.lang.InterruptedException
- Throws:
java.lang.InterruptedException
-
getIngestionIsolationPropertyMap
public static java.util.Map<java.lang.String,java.lang.Object> getIngestionIsolationPropertyMap()
-
getUniqueTopicString
public static java.lang.String getUniqueTopicString(java.lang.String prefix)
-
getFreePort
public static int getFreePort()
WARNING: The code which generates the free port and uses it must always be called within a try/catch and a loop. There is no guarantee that the port returned will still be available at the time it is used. This is best-effort only.- Returns:
- a free port to be used by tests.
-
mergeConfigs
public static java.util.Map<java.lang.String,java.lang.String> mergeConfigs(java.util.List<java.util.Map<java.lang.String,java.lang.String>> configMaps)
-
checkMissingFieldInAvroRecord
public static void checkMissingFieldInAvroRecord(org.apache.avro.generic.GenericRecord record, java.lang.String fieldName)
-
findFoldersWithFileExtension
public static java.util.List<java.lang.String> findFoldersWithFileExtension(java.io.File directory, java.lang.String fileExtension)
-
searchForFileExtension
public static java.util.List<java.lang.String> searchForFileExtension(java.io.File directory, java.lang.String fileExtension)
-
directoryContainsFolder
public static boolean directoryContainsFolder(java.lang.String directoryPath, java.lang.String folderName)
-
deleteDirectory
public static void deleteDirectory(java.io.File fileToDelete)
-
loadFileAsString
public static java.lang.String loadFileAsString(java.lang.String fileName)
-
-