From 3b887e25c75cee373f11002ef645ed4f6f930955 Mon Sep 17 00:00:00 2001 From: Leonid Stryuk <=> Date: Tue, 17 Dec 2024 15:46:17 +0100 Subject: [PATCH] Fixed the flacky test --- .../exodus/entitystore/WrongUsernameTest.kt | 1 + .../entitystore/orientdb/EncryptedDBTest.kt | 32 ++++++++++++++++--- 2 files changed, 28 insertions(+), 5 deletions(-) diff --git a/entity-store/src/test/kotlin/jetbrains/exodus/entitystore/WrongUsernameTest.kt b/entity-store/src/test/kotlin/jetbrains/exodus/entitystore/WrongUsernameTest.kt index afa56657b..b082009f1 100644 --- a/entity-store/src/test/kotlin/jetbrains/exodus/entitystore/WrongUsernameTest.kt +++ b/entity-store/src/test/kotlin/jetbrains/exodus/entitystore/WrongUsernameTest.kt @@ -28,6 +28,7 @@ class WrongUsernameTest { fun cannotCreateDatabaseWithWrongUsername() { val cfg = ODatabaseConnectionConfig .builder() + .withPassword("hello") .withUserName(";drop database users") .withDatabaseType(ODatabaseType.MEMORY) .withDatabaseRoot(Files.createTempDirectory("haha").absolutePathString()) diff --git a/entity-store/src/test/kotlin/jetbrains/exodus/entitystore/orientdb/EncryptedDBTest.kt b/entity-store/src/test/kotlin/jetbrains/exodus/entitystore/orientdb/EncryptedDBTest.kt index 68b26df98..bf7ac2ad4 100644 --- a/entity-store/src/test/kotlin/jetbrains/exodus/entitystore/orientdb/EncryptedDBTest.kt +++ b/entity-store/src/test/kotlin/jetbrains/exodus/entitystore/orientdb/EncryptedDBTest.kt @@ -25,12 +25,23 @@ import mu.KLogging import org.junit.After import org.junit.Assert import org.junit.Test +import org.junit.runner.RunWith +import org.junit.runners.Parameterized +import java.lang.AssertionError import java.nio.file.Files import java.util.* import kotlin.io.path.absolutePathString -class EncryptedDBTest { - companion object : KLogging() +@RunWith(Parameterized::class) +class EncryptedDBTest(val number: Int) { + companion object : KLogging() { + @JvmStatic + @Parameterized.Parameters + fun data(): Collection> { + return Arrays.asList>(*Array(5) { arrayOf(0) }) // Repeat 20 times + } + } + lateinit var provider: ODatabaseProviderImpl lateinit var db: OrientDB @@ -43,7 +54,7 @@ class EncryptedDBTest { .withPassword(password) .withUserName(username) .withDatabaseType(ODatabaseType.PLOCAL) - .withDatabaseRoot(Files.createTempDirectory("oxigenDB_test").absolutePathString()) + .withDatabaseRoot(Files.createTempDirectory("oxigenDB_test$number").absolutePathString()) .build() return ODatabaseConfig.builder() @@ -62,11 +73,13 @@ class EncryptedDBTest { } val config = createConfig(cipherKey) val noEncryptionConfig = createConfig(null) + logger.info("Connect to db and create test vertex class") db = initOrientDbServer(config.connectionConfig) provider = ODatabaseProviderImpl(config, db) provider.withSession { session -> session.createVertexClass("TEST") } + logger.info("Set vertex property") provider.withSession { session -> session.executeInTx { val vertex = session.newVertex("TEST") @@ -75,7 +88,9 @@ class EncryptedDBTest { } } db.close() + logger.info("Close the DB") Thread.sleep(1000) + logger.info("Connect to db one more time and read") db = initOrientDbServer(config.connectionConfig) provider = ODatabaseProviderImpl(config, db) provider.withSession { session -> @@ -84,8 +99,10 @@ class EncryptedDBTest { Assert.assertEquals(1, vertex.size) } } + logger.info("Close the DB") db.close() Thread.sleep(1000) + logger.info("Connect to db one more time without encryption") db = initOrientDbServer(config.connectionConfig) try { ODatabaseProviderImpl(noEncryptionConfig, db).apply { @@ -99,6 +116,11 @@ class EncryptedDBTest { } } catch (_: OStorageException) { logger.info("As expected DB failed to initialize without key") + } catch (e: AssertionError) { + logger.info("As expected DB failed to initialize without key") + } catch (e: Throwable) { + logger.error("DB failed with unexpected error", e) + Assert.fail("Wrong error") } } @@ -106,10 +128,10 @@ class EncryptedDBTest { fun close() { db.close() try { - if (!Orient.instance().isActive){ + if (!Orient.instance().isActive) { Orient.instance().startup() } - } catch (_: Throwable){ + } catch (_: Throwable) { logger.error("CANNOT REINIT OXIGENDB") } }