Skip to content

Commit

Permalink
Fixed the flacky test
Browse files Browse the repository at this point in the history
  • Loading branch information
Leonid Stryuk committed Dec 17, 2024
1 parent 3d3db5c commit 3b887e2
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Array<Any>> {
return Arrays.asList<Array<Any>>(*Array(5) { arrayOf(0) }) // Repeat 20 times
}
}

lateinit var provider: ODatabaseProviderImpl
lateinit var db: OrientDB

Expand All @@ -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()
Expand All @@ -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")
Expand All @@ -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 ->
Expand All @@ -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 {
Expand All @@ -99,17 +116,22 @@ 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")
}
}

@After
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")
}
}
Expand Down

0 comments on commit 3b887e2

Please sign in to comment.