Skip to content

Commit

Permalink
finos#1196 fix intermittently failing tests
Browse files Browse the repository at this point in the history
- with this fix we also improve performance for IgniteOrderStoreTest
  as now we only clear cache instead of restarting whole ignite before
  each test.
  • Loading branch information
junaidzm13 committed Feb 21, 2024
1 parent ff550f7 commit 9badfe0
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ package org.finos.vuu.example.ignite
import org.apache.ignite.cache.query.IndexQueryCriteriaBuilder
import org.apache.ignite.{Ignite, IgniteCache}
import org.finos.vuu.core.module.simul.model.{ChildOrder, ParentOrder}
import org.scalatest.BeforeAndAfter
import org.scalatest.{BeforeAndAfterAll, BeforeAndAfterEach}
import org.scalatest.funsuite.AnyFunSuiteLike
import org.scalatest.matchers.should.Matchers

class IgniteOrderStoreTest extends AnyFunSuiteLike with BeforeAndAfter with Matchers {
class IgniteOrderStoreTest extends AnyFunSuiteLike with BeforeAndAfterAll with BeforeAndAfterEach with Matchers {
private var ignite: Ignite = _
private var parentOrderCache: IgniteCache[Int, ParentOrder] = _
private var childOrderCache: IgniteCache[Int, ChildOrder] = _
Expand All @@ -16,13 +16,18 @@ class IgniteOrderStoreTest extends AnyFunSuiteLike with BeforeAndAfter with Matc
private val emptySortQueries: String = ""
private val emptyFilterQueries: String = ""

before {
ignite = TestUtils.setupIgnite()
override def beforeAll(): Unit = {
ignite = TestUtils.setupIgnite(testName = this.toString)
parentOrderCache = ignite.getOrCreateCache("parentOrderCache")
childOrderCache = ignite.getOrCreateCache("childOrderCache")
orderStore = new IgniteOrderStore(parentOrderCache, childOrderCache)
}

override def beforeEach(): Unit = {
childOrderCache.clear()
parentOrderCache.clear()
}

test("Ignite Store And Find Order") {
GivenParentOrder(1)

Expand Down Expand Up @@ -137,12 +142,12 @@ class IgniteOrderStoreTest extends AnyFunSuiteLike with BeforeAndAfter with Matc
var parentOrder2: ParentOrder = GivenParentOrder(2)
parentOrder2 = GivenParentHasChildOrder(parentOrder2, 2)

val sortByValues = "parentId ASC"
val sortByValues = "id ASC"
val childOrder = orderStore.findChildOrder(emptyFilterQueries, sortByValues, 100, 0).toList

assert(childOrder != null)
assert(childOrder.size == 3)
childOrder.map(c => c.id).toArray shouldBe Array(1,3,2)
childOrder.map(c => c.id).toArray shouldBe Array(1,2,3)
}

test("Ignite Store With Custom Sql Sort Multiple Columns") {
Expand Down Expand Up @@ -225,7 +230,7 @@ class IgniteOrderStoreTest extends AnyFunSuiteLike with BeforeAndAfter with Matc
updatedParentOrder
}

after {
override def afterAll(): Unit = {
ignite.close()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,9 @@ object TestUtils {
activeChildren = 0)
}

def setupIgnite(): Ignite = {
def setupIgnite(testName: String): Ignite = {
val igniteConfiguration = new IgniteConfiguration()
igniteConfiguration.setIgniteInstanceName(testName)

val parentOrderCacheConfiguration = new org.apache.ignite.configuration.CacheConfiguration[Int, ParentOrder]
val childOrderCacheConfiguration = new org.apache.ignite.configuration.CacheConfiguration[Int, ChildOrder]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package org.finos.vuu.example.ignite.provider

import org.apache.ignite.IgniteCache
import org.apache.ignite.Ignite
import org.finos.vuu.core.module.simul.model.{ChildOrder, ParentOrder}
import org.finos.vuu.core.sort.SortDirection
import org.finos.vuu.example.ignite.module.IgniteOrderDataModule
Expand All @@ -10,17 +10,27 @@ import org.finos.vuu.net.FilterSpec
import org.finos.vuu.util.schema.SchemaMapper
import org.scalatest.funsuite.AnyFunSuiteLike
import org.scalatest.matchers.should.Matchers
import org.scalatest.BeforeAndAfterAll

class IgniteOrderDataQueryFunctionalTest extends AnyFunSuiteLike with Matchers {

private val ignite = TestUtils.setupIgnite()
private val parentOrderCache: IgniteCache[Int, ParentOrder] = ignite.getOrCreateCache("parentOrderCache")
private val childOrderCache: IgniteCache[Int, ChildOrder] = ignite.getOrCreateCache("childOrderCache")
private val orderStore = new IgniteOrderStore(parentOrderCache, childOrderCache)
class IgniteOrderDataQueryFunctionalTest extends AnyFunSuiteLike with BeforeAndAfterAll with Matchers {
private val schemaMapper = SchemaMapper(ChildOrderEntityObject.getSchema, IgniteOrderDataModule.columns, IgniteOrderDataProvider.columnNameByExternalField)
private val dataQuery = IgniteOrderDataQuery(orderStore, schemaMapper)
private var ignite: Ignite = _
private var orderStore: IgniteOrderStore = _
private var dataQuery: IgniteOrderDataQuery = _

override def beforeAll(): Unit = {
ignite = TestUtils.setupIgnite(testName = this.toString)
val parentOrderCache = ignite.getOrCreateCache[Int, ParentOrder]("parentOrderCache")
val childOrderCache = ignite.getOrCreateCache[Int, ChildOrder]("childOrderCache")
orderStore = new IgniteOrderStore(parentOrderCache, childOrderCache)
dataQuery = IgniteOrderDataQuery(orderStore, schemaMapper)
}

override def afterAll(): Unit = {
ignite.close()
}

test("Can parse and apply filtering and sorting when fetching") {
test("Can parse and apply filters and sort when fetching") {
val testOrder1 = TestUtils.createChildOrder(1, ric = "ABC.HK", price = 5.55)
val testOrder2 = TestUtils.createChildOrder(2, ric = "ABC.LDN", price = 6.0)
val testOrder3 = TestUtils.createChildOrder(3, ric = "ABC.NY", price = 4.5)
Expand Down

0 comments on commit 9badfe0

Please sign in to comment.