Skip to content

Commit

Permalink
#862 Fixed test versions to abstract out clock.
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisjstevo committed Nov 5, 2023
1 parent 76d1ad2 commit 219b7f3
Show file tree
Hide file tree
Showing 18 changed files with 568 additions and 2,506 deletions.
2,224 changes: 4 additions & 2,220 deletions vuu-ui/packages/vuu-data/src/inlined-worker.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion vuu/src/main/resources/runconfigurations/SimulMain.run.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="SimulMain" type="Application" factoryName="Application" folderName="runConfigs">
<option name="ALTERNATIVE_JRE_PATH" value="17" />
<option name="ALTERNATIVE_JRE_PATH" value="temurin-11" />
<option name="ALTERNATIVE_JRE_PATH_ENABLED" value="true" />
<option name="MAIN_CLASS_NAME" value="org.finos.vuu.SimulMain" />
<module name="vuu" />
Expand Down
4 changes: 2 additions & 2 deletions vuu/src/main/scala/org/finos/vuu/provider/MockProvider.scala
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import org.finos.toolbox.time.Clock

import java.util.concurrent.ConcurrentHashMap

class MockProvider(table: DataTable)(implicit timeProvider: Clock, lifecycle: LifecycleContainer) extends Provider with StrictLogging {
class MockProvider(table: DataTable)(implicit clock: Clock, lifecycle: LifecycleContainer) extends Provider with StrictLogging {

lifecycle(this)

Expand All @@ -22,7 +22,7 @@ class MockProvider(table: DataTable)(implicit timeProvider: Clock, lifecycle: Li
}

def tick(key: String, row: Map[String, Any]) =
table.processUpdate(key, new RowWithData(key, row), timeProvider.now())
table.processUpdate(key, new RowWithData(key, row), clock.now())

def delete(key: String) = {
table.processDelete(key)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,19 @@ object TestTimeStamp{

class AbstractViewPortTestCase extends AnyFeatureSpec {

implicit val timeProvider: Clock = new TestFriendlyClock(1311544800)
implicit val metrics: MetricsProvider = new MetricsProviderImpl

def filterByVpId(vpUps: Seq[ViewPortUpdate], vp: ViewPort): Seq[ViewPortUpdate] = {
vpUps.filter( vpu => vpu.vp.id == vp.id )
}

def setupViewPort(tableContainer: TableContainer, providerContainer: ProviderContainer): ViewPortContainer = {
def setupViewPort(tableContainer: TableContainer, providerContainer: ProviderContainer)(implicit clock: Clock, metrics: MetricsProvider): ViewPortContainer = {

val viewPortContainer = new ViewPortContainer(tableContainer, providerContainer)

viewPortContainer
}

def createDefaultViewPortInfra(): (ViewPortContainer, DataTable, MockProvider, ClientSessionId, OutboundRowPublishQueue) = {
def createDefaultViewPortInfra()(implicit clock: Clock, metrics: MetricsProvider): (ViewPortContainer, DataTable, MockProvider, ClientSessionId, OutboundRowPublishQueue) = {
implicit val lifecycle: LifecycleContainer = new LifecycleContainer

val dateTime = 1437728400000L//new LocalDateTime(2015, 7, 24, 11, 0).toDateTime.toInstant.getMillis
Expand Down Expand Up @@ -83,7 +81,7 @@ class AbstractViewPortTestCase extends AnyFeatureSpec {



def createDefaultOrderPricesViewPortInfra(): (ViewPortContainer, DataTable, MockProvider, DataTable, MockProvider, ClientSessionId, OutboundRowPublishQueue) = {
def createDefaultOrderPricesViewPortInfra()(implicit clock: Clock, metrics: MetricsProvider): (ViewPortContainer, DataTable, MockProvider, DataTable, MockProvider, ClientSessionId, OutboundRowPublishQueue) = {
implicit val lifecycle = new LifecycleContainer

val dateTime = 1437728400000L//new LocalDateTime(2015, 7, 24, 11, 0).toDateTime.toInstant.getMillis
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package org.finos.vuu.viewport

import org.finos.toolbox.jmx.{MetricsProvider, MetricsProviderImpl}
import org.finos.toolbox.time.{Clock, TestFriendlyClock}
import org.finos.vuu.client.messages.RequestId
import org.finos.vuu.core.table.TableTestHelper.combineQs
import org.finos.vuu.core.table.ViewPortColumnCreator
Expand All @@ -10,6 +12,9 @@ import org.scalatest.prop.Tables.Table

class CalculatedColumnsViewPortTest extends AbstractViewPortTestCase with Matchers with GivenWhenThen {

implicit val clock: Clock = new TestFriendlyClock(TestTimeStamp.EPOCH_DEFAULT)
implicit val metrics: MetricsProvider = new MetricsProviderImpl

Feature("Create a Viewport with calc on a non-existant column") {

Scenario("Scenario 1") {
Expand All @@ -19,7 +24,7 @@ class CalculatedColumnsViewPortTest extends AbstractViewPortTestCase with Matche

val viewPortColumns = ViewPortColumnCreator.create(orders, List("orderId", "trader", "tradeTime", "quantity", "ric", "logicTest:String:=if(fooBar = 109, \"Yay\", \"Boo\")"))

createNOrderRowsNoSleep(ordersProvider, 10)(timeProvider)
createNOrderRowsNoSleep(ordersProvider, 10)(clock)

val viewPort = viewPortContainer.create(RequestId.oneNew(), session, outQueue, orders, ViewPortRange(0, 10), viewPortColumns)

Expand All @@ -31,17 +36,17 @@ class CalculatedColumnsViewPortTest extends AbstractViewPortTestCase with Matche
//it should return a compound error
assertVpEq(combinedUpdates) {
Table(
("orderId", "trader", "ric", "tradeTime", "quantity", "logicTest"),
("NYC-0000", "chris", "VOD.L", 1311544800L, 100, "Boo"),
("NYC-0001", "chris", "VOD.L", 1311544800L, 101, "Boo"),
("NYC-0002", "chris", "VOD.L", 1311544800L, 102, "Boo"),
("NYC-0003", "chris", "VOD.L", 1311544800L, 103, "Boo"),
("NYC-0004", "chris", "VOD.L", 1311544800L, 104, "Boo"),
("NYC-0005", "chris", "VOD.L", 1311544800L, 105, "Boo"),
("NYC-0006", "chris", "VOD.L", 1311544800L, 106, "Boo"),
("NYC-0007", "chris", "VOD.L", 1311544800L, 107, "Boo"),
("NYC-0008", "chris", "VOD.L", 1311544800L, 108, "Boo"),
("NYC-0009", "chris", "VOD.L", 1311544800L, 109, "Boo")
("orderId" ,"trader" ,"ric" ,"tradeTime","quantity","logicTest"),
("NYC-0000","chris" ,"VOD.L" ,1311544800000L,100 ,"Boo" ),
("NYC-0001","chris" ,"VOD.L" ,1311544800000L,101 ,"Boo" ),
("NYC-0002","chris" ,"VOD.L" ,1311544800000L,102 ,"Boo" ),
("NYC-0003","chris" ,"VOD.L" ,1311544800000L,103 ,"Boo" ),
("NYC-0004","chris" ,"VOD.L" ,1311544800000L,104 ,"Boo" ),
("NYC-0005","chris" ,"VOD.L" ,1311544800000L,105 ,"Boo" ),
("NYC-0006","chris" ,"VOD.L" ,1311544800000L,106 ,"Boo" ),
("NYC-0007","chris" ,"VOD.L" ,1311544800000L,107 ,"Boo" ),
("NYC-0008","chris" ,"VOD.L" ,1311544800000L,108 ,"Boo" ),
("NYC-0009","chris" ,"VOD.L" ,1311544800000L,109 ,"Boo" )
)
}
}
Expand All @@ -56,7 +61,7 @@ class CalculatedColumnsViewPortTest extends AbstractViewPortTestCase with Matche

val viewPortColumns = ViewPortColumnCreator.create(orders, List("orderId", "trader", "tradeTime", "quantity", "ric", "logicTest:String:=if(quantity = 109, \"Yay\", \"Boo\")"))

createNOrderRowsNoSleep(ordersProvider, 10)(timeProvider)
createNOrderRowsNoSleep(ordersProvider, 10)(clock)

val viewPort = viewPortContainer.create(RequestId.oneNew(), session, outQueue, orders, ViewPortRange(0, 10), viewPortColumns)

Expand All @@ -66,17 +71,17 @@ class CalculatedColumnsViewPortTest extends AbstractViewPortTestCase with Matche

assertVpEq(combinedUpdates) {
Table(
("orderId", "trader", "ric", "tradeTime", "quantity", "logicTest"),
("NYC-0000", "chris", "VOD.L", 1311544800L, 100, "Boo"),
("NYC-0001", "chris", "VOD.L", 1311544800L, 101, "Boo"),
("NYC-0002", "chris", "VOD.L", 1311544800L, 102, "Boo"),
("NYC-0003", "chris", "VOD.L", 1311544800L, 103, "Boo"),
("NYC-0004", "chris", "VOD.L", 1311544800L, 104, "Boo"),
("NYC-0005", "chris", "VOD.L", 1311544800L, 105, "Boo"),
("NYC-0006", "chris", "VOD.L", 1311544800L, 106, "Boo"),
("NYC-0007", "chris", "VOD.L", 1311544800L, 107, "Boo"),
("NYC-0008", "chris", "VOD.L", 1311544800L, 108, "Boo"),
("NYC-0009", "chris", "VOD.L", 1311544800L, 109, "Yay")
("orderId" ,"trader" ,"ric" ,"tradeTime","quantity","logicTest"),
("NYC-0000","chris" ,"VOD.L" ,1311544800000L,100 ,"Boo" ),
("NYC-0001","chris" ,"VOD.L" ,1311544800000L,101 ,"Boo" ),
("NYC-0002","chris" ,"VOD.L" ,1311544800000L,102 ,"Boo" ),
("NYC-0003","chris" ,"VOD.L" ,1311544800000L,103 ,"Boo" ),
("NYC-0004","chris" ,"VOD.L" ,1311544800000L,104 ,"Boo" ),
("NYC-0005","chris" ,"VOD.L" ,1311544800000L,105 ,"Boo" ),
("NYC-0006","chris" ,"VOD.L" ,1311544800000L,106 ,"Boo" ),
("NYC-0007","chris" ,"VOD.L" ,1311544800000L,107 ,"Boo" ),
("NYC-0008","chris" ,"VOD.L" ,1311544800000L,108 ,"Boo" ),
("NYC-0009","chris" ,"VOD.L" ,1311544800000L,109 ,"Yay" )
)
}
}
Expand All @@ -90,7 +95,7 @@ class CalculatedColumnsViewPortTest extends AbstractViewPortTestCase with Matche

val viewPortColumns = ViewPortColumnCreator.create(orders, List("orderId", "trader", "tradeTime", "quantity", "ric", "quantityTimes100:Long:=quantity*100"))

createNOrderRowsNoSleep(ordersProvider, 10)(timeProvider)
createNOrderRowsNoSleep(ordersProvider, 10)(clock)

val viewPort = viewPortContainer.create(RequestId.oneNew(), session, outQueue, orders, ViewPortRange(0, 10), viewPortColumns)

Expand All @@ -100,17 +105,17 @@ class CalculatedColumnsViewPortTest extends AbstractViewPortTestCase with Matche

assertVpEq(combinedUpdates) {
Table(
("orderId", "trader", "ric", "tradeTime", "quantity", "quantityTimes100"),
("NYC-0000", "chris", "VOD.L", 1311544800L, 100, 10000),
("NYC-0001", "chris", "VOD.L", 1311544800L, 101, 10100),
("NYC-0002", "chris", "VOD.L", 1311544800L, 102, 10200),
("NYC-0003", "chris", "VOD.L", 1311544800L, 103, 10300),
("NYC-0004", "chris", "VOD.L", 1311544800L, 104, 10400),
("NYC-0005", "chris", "VOD.L", 1311544800L, 105, 10500),
("NYC-0006", "chris", "VOD.L", 1311544800L, 106, 10600),
("NYC-0007", "chris", "VOD.L", 1311544800L, 107, 10700),
("NYC-0008", "chris", "VOD.L", 1311544800L, 108, 10800),
("NYC-0009", "chris", "VOD.L", 1311544800L, 109, 10900)
("orderId" ,"trader" ,"ric" ,"tradeTime","quantity","quantityTimes100"),
("NYC-0000","chris" ,"VOD.L" ,1311544800000L,100 ,10000 ),
("NYC-0001","chris" ,"VOD.L" ,1311544800000L,101 ,10100 ),
("NYC-0002","chris" ,"VOD.L" ,1311544800000L,102 ,10200 ),
("NYC-0003","chris" ,"VOD.L" ,1311544800000L,103 ,10300 ),
("NYC-0004","chris" ,"VOD.L" ,1311544800000L,104 ,10400 ),
("NYC-0005","chris" ,"VOD.L" ,1311544800000L,105 ,10500 ),
("NYC-0006","chris" ,"VOD.L" ,1311544800000L,106 ,10600 ),
("NYC-0007","chris" ,"VOD.L" ,1311544800000L,107 ,10700 ),
("NYC-0008","chris" ,"VOD.L" ,1311544800000L,108 ,10800 ),
("NYC-0009","chris" ,"VOD.L" ,1311544800000L,109 ,10900 )
)
}

Expand All @@ -125,17 +130,17 @@ class CalculatedColumnsViewPortTest extends AbstractViewPortTestCase with Matche

assertVpEq(combinedUpdates2) {
Table(
("orderId", "trader", "ric", "tradeTime", "quantity", "textConcat"),
("NYC-0000", "chris", "VOD.L", 1311544800L, 100, "NYC-0000VOD.L"),
("NYC-0001", "chris", "VOD.L", 1311544800L, 101, "NYC-0001VOD.L"),
("NYC-0002", "chris", "VOD.L", 1311544800L, 102, "NYC-0002VOD.L"),
("NYC-0003", "chris", "VOD.L", 1311544800L, 103, "NYC-0003VOD.L"),
("NYC-0004", "chris", "VOD.L", 1311544800L, 104, "NYC-0004VOD.L"),
("NYC-0005", "chris", "VOD.L", 1311544800L, 105, "NYC-0005VOD.L"),
("NYC-0006", "chris", "VOD.L", 1311544800L, 106, "NYC-0006VOD.L"),
("NYC-0007", "chris", "VOD.L", 1311544800L, 107, "NYC-0007VOD.L"),
("NYC-0008", "chris", "VOD.L", 1311544800L, 108, "NYC-0008VOD.L"),
("NYC-0009", "chris", "VOD.L", 1311544800L, 109, "NYC-0009VOD.L")
("orderId" ,"trader" ,"ric" ,"tradeTime","quantity","textConcat"),
("NYC-0000","chris" ,"VOD.L" ,1311544800000L,100 ,"NYC-0000VOD.L"),
("NYC-0001","chris" ,"VOD.L" ,1311544800000L,101 ,"NYC-0001VOD.L"),
("NYC-0002","chris" ,"VOD.L" ,1311544800000L,102 ,"NYC-0002VOD.L"),
("NYC-0003","chris" ,"VOD.L" ,1311544800000L,103 ,"NYC-0003VOD.L"),
("NYC-0004","chris" ,"VOD.L" ,1311544800000L,104 ,"NYC-0004VOD.L"),
("NYC-0005","chris" ,"VOD.L" ,1311544800000L,105 ,"NYC-0005VOD.L"),
("NYC-0006","chris" ,"VOD.L" ,1311544800000L,106 ,"NYC-0006VOD.L"),
("NYC-0007","chris" ,"VOD.L" ,1311544800000L,107 ,"NYC-0007VOD.L"),
("NYC-0008","chris" ,"VOD.L" ,1311544800000L,108 ,"NYC-0008VOD.L"),
("NYC-0009","chris" ,"VOD.L" ,1311544800000L,109 ,"NYC-0009VOD.L")
)
}
}
Expand All @@ -150,7 +155,7 @@ class CalculatedColumnsViewPortTest extends AbstractViewPortTestCase with Matche

val viewPortColumns = ViewPortColumnCreator.create(orders, List("orderId", "trader", "tradeTime", "quantity", "ric"))

createNOrderRowsNoSleep(ordersProvider, 10)(timeProvider)
createNOrderRowsNoSleep(ordersProvider, 10)(clock)

val viewPort = viewPortContainer.create(RequestId.oneNew(), session, outQueue, orders, ViewPortRange(0, 10), viewPortColumns)

Expand All @@ -160,17 +165,17 @@ class CalculatedColumnsViewPortTest extends AbstractViewPortTestCase with Matche

assertVpEq(combinedUpdates) {
Table(
("orderId", "trader", "ric", "tradeTime", "quantity"),
("NYC-0000", "chris", "VOD.L", 1311544800L, 100),
("NYC-0001", "chris", "VOD.L", 1311544800L, 101),
("NYC-0002", "chris", "VOD.L", 1311544800L, 102),
("NYC-0003", "chris", "VOD.L", 1311544800L, 103),
("NYC-0004", "chris", "VOD.L", 1311544800L, 104),
("NYC-0005", "chris", "VOD.L", 1311544800L, 105),
("NYC-0006", "chris", "VOD.L", 1311544800L, 106),
("NYC-0007", "chris", "VOD.L", 1311544800L, 107),
("NYC-0008", "chris", "VOD.L", 1311544800L, 108),
("NYC-0009", "chris", "VOD.L", 1311544800L, 109)
("orderId" ,"trader" ,"ric" ,"tradeTime","quantity"),
("NYC-0000","chris" ,"VOD.L" ,1311544800000L,100 ),
("NYC-0001","chris" ,"VOD.L" ,1311544800000L,101 ),
("NYC-0002","chris" ,"VOD.L" ,1311544800000L,102 ),
("NYC-0003","chris" ,"VOD.L" ,1311544800000L,103 ),
("NYC-0004","chris" ,"VOD.L" ,1311544800000L,104 ),
("NYC-0005","chris" ,"VOD.L" ,1311544800000L,105 ),
("NYC-0006","chris" ,"VOD.L" ,1311544800000L,106 ),
("NYC-0007","chris" ,"VOD.L" ,1311544800000L,107 ),
("NYC-0008","chris" ,"VOD.L" ,1311544800000L,108 ),
("NYC-0009","chris" ,"VOD.L" ,1311544800000L,109 )
)
}

Expand All @@ -182,17 +187,17 @@ class CalculatedColumnsViewPortTest extends AbstractViewPortTestCase with Matche

assertVpEq(combinedUpdates2) {
Table(
("orderId", "trader", "ric", "tradeTime", "quantity", "textConcat"),
("NYC-0000", "chris", "VOD.L", 1311544800L, 100, "NYC-0000VOD.L"),
("NYC-0001", "chris", "VOD.L", 1311544800L, 101, "NYC-0001VOD.L"),
("NYC-0002", "chris", "VOD.L", 1311544800L, 102, "NYC-0002VOD.L"),
("NYC-0003", "chris", "VOD.L", 1311544800L, 103, "NYC-0003VOD.L"),
("NYC-0004", "chris", "VOD.L", 1311544800L, 104, "NYC-0004VOD.L"),
("NYC-0005", "chris", "VOD.L", 1311544800L, 105, "NYC-0005VOD.L"),
("NYC-0006", "chris", "VOD.L", 1311544800L, 106, "NYC-0006VOD.L"),
("NYC-0007", "chris", "VOD.L", 1311544800L, 107, "NYC-0007VOD.L"),
("NYC-0008", "chris", "VOD.L", 1311544800L, 108, "NYC-0008VOD.L"),
("NYC-0009", "chris", "VOD.L", 1311544800L, 109, "NYC-0009VOD.L")
("orderId" ,"trader" ,"ric" ,"tradeTime","quantity","textConcat"),
("NYC-0000","chris" ,"VOD.L" ,1311544800000L,100 ,"NYC-0000VOD.L"),
("NYC-0001","chris" ,"VOD.L" ,1311544800000L,101 ,"NYC-0001VOD.L"),
("NYC-0002","chris" ,"VOD.L" ,1311544800000L,102 ,"NYC-0002VOD.L"),
("NYC-0003","chris" ,"VOD.L" ,1311544800000L,103 ,"NYC-0003VOD.L"),
("NYC-0004","chris" ,"VOD.L" ,1311544800000L,104 ,"NYC-0004VOD.L"),
("NYC-0005","chris" ,"VOD.L" ,1311544800000L,105 ,"NYC-0005VOD.L"),
("NYC-0006","chris" ,"VOD.L" ,1311544800000L,106 ,"NYC-0006VOD.L"),
("NYC-0007","chris" ,"VOD.L" ,1311544800000L,107 ,"NYC-0007VOD.L"),
("NYC-0008","chris" ,"VOD.L" ,1311544800000L,108 ,"NYC-0008VOD.L"),
("NYC-0009","chris" ,"VOD.L" ,1311544800000L,109 ,"NYC-0009VOD.L")
)
}

Expand Down
17 changes: 11 additions & 6 deletions vuu/src/test/scala/org/finos/vuu/viewport/DeleteViewPortTest.scala
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package org.finos.vuu.viewport

import org.finos.toolbox.jmx.{MetricsProvider, MetricsProviderImpl}
import org.finos.toolbox.time.{Clock, TestFriendlyClock}
import org.finos.vuu.client.messages.RequestId
import org.finos.vuu.core.table.TableTestHelper.combineQs
import org.finos.vuu.core.table.ViewPortColumnCreator
Expand All @@ -10,6 +12,9 @@ import org.scalatest.prop.Tables.Table

class DeleteViewPortTest extends AbstractViewPortTestCase with Matchers with GivenWhenThen {

implicit val clock: Clock = new TestFriendlyClock(TestTimeStamp.EPOCH_DEFAULT)
implicit val metrics: MetricsProvider = new MetricsProviderImpl

Feature("Check when we delete a viewport, it is removed and no further ticks are sent") {

Scenario("Create viewport delete it, check no further ticks") {
Expand All @@ -18,7 +23,7 @@ class DeleteViewPortTest extends AbstractViewPortTestCase with Matchers with Giv

val vpcolumns = ViewPortColumnCreator.create(orders, List("orderId", "trader", "tradeTime", "quantity", "ric"))//.map(orders.getTableDef.columnForName(_)).toList

createNOrderRows(ordersProvider, 10)(timeProvider)
createNOrderRows(ordersProvider, 10)(clock)

val viewPort = viewPortContainer.create(RequestId.oneNew(), session, outQueue, orders, ViewPortRange(0, 4), vpcolumns)

Expand All @@ -30,11 +35,11 @@ class DeleteViewPortTest extends AbstractViewPortTestCase with Matchers with Giv

assertVpEq(combinedUpdates) {
Table(
("orderId", "trader", "ric", "tradeTime", "quantity"),
("NYC-0000", "chris", "VOD.L", 1311544800L, 100),
("NYC-0001", "chris", "VOD.L", 1311544810L, 101),
("NYC-0002", "chris", "VOD.L", 1311544820L, 102),
("NYC-0003", "chris", "VOD.L", 1311544830L, 103)
("orderId" ,"trader" ,"ric" ,"tradeTime","quantity"),
("NYC-0000","chris" ,"VOD.L" ,1311544800000L,100 ),
("NYC-0001","chris" ,"VOD.L" ,1311544800010L,101 ),
("NYC-0002","chris" ,"VOD.L" ,1311544800020L,102 ),
("NYC-0003","chris" ,"VOD.L" ,1311544800030L,103 )
)
}

Expand Down
Loading

0 comments on commit 219b7f3

Please sign in to comment.