Skip to content

Commit

Permalink
Merge pull request #78 from team5499/dev/startup
Browse files Browse the repository at this point in the history
Startup time fix
  • Loading branch information
andycate authored Mar 8, 2019
2 parents 10ed8ef + dc312ad commit 79102e1
Show file tree
Hide file tree
Showing 6 changed files with 300 additions and 13 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ dependencies {
}

group = 'org.team5499'
version = '0.12.0' /* Change this when deploying a new version */
version = '0.12.1' /* Change this when deploying a new version */

task sourcesJar(type: Jar) {
from sourceSets.main.allJava
Expand Down
4 changes: 4 additions & 0 deletions src/main/kotlin/org/team5499/dashboard/Dashboard.kt
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,10 @@ object Dashboard {
SocketHandler.startBroadcastThread() // start broadcasting data
}

fun waitForInitialization() {
Spark.awaitInitialization()
}

/**
* Stop the dashboard and wait for it to shutdown
*/
Expand Down
21 changes: 10 additions & 11 deletions src/main/kotlin/org/team5499/dashboard/DashboardVar.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import kotlin.reflect.full.memberProperties
import kotlin.reflect.KVisibility
import kotlin.reflect.KMutableProperty

class DashboardVar<T>(var initValue: T) {
class DashboardVar<T>(val initValue: T) {

companion object {
@SuppressWarnings("EmptyCatchBlock", "TooGenericExceptionCaught")
Expand All @@ -25,25 +25,24 @@ class DashboardVar<T>(var initValue: T) {
}
}

var isInit = false
var dashName = ""

fun getDashName(thisRef: Any?, property: KProperty<*>): String {
val packageLength = thisRef!!::class.java.getPackage().name.length
return "${thisRef::class.qualifiedName!!.substring(packageLength + 1)}.${property.name}"
}

operator fun provideDelegate(thisRef: Any?, property: KProperty<*>): DashboardVar<T> {
dashName = getDashName(thisRef, property)
Dashboard.setVariable(dashName, initValue as Any)
return this
}

operator fun getValue(thisRef: Any?, property: KProperty<*>): T {
if (!isInit) {
Dashboard.setVariable(getDashName(thisRef, property), initValue as Any)
isInit = true
println(getDashName(thisRef, property))
return initValue
}
return Dashboard.getVariable(getDashName(thisRef, property))
return Dashboard.getVariable(dashName)
}

operator fun setValue(thisRef: Any?, property: KProperty<*>, value: T) {
isInit = true
Dashboard.setVariable(getDashName(thisRef, property), value as Any)
Dashboard.setVariable(dashName, value as Any)
}
}
19 changes: 18 additions & 1 deletion src/test/kotlin/tests/NestedVariableTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class NestedVariableTest {
@JvmStatic
fun initDashboard() {
Dashboard.start(this, "playgroundConf.json")
Dashboard.waitForInitialization()
Constants.initConstants()
}

Expand Down Expand Up @@ -76,22 +77,38 @@ class NestedVariableTest {
object Constants {

public fun initConstants() {
DashboardVar.initClassProps(Constants::class)
println("init props")
First.initProps()
Second.initProps()
Nest.initProps()
}

public var PROP by DashboardVar(1.0)

object First {
fun initProps() {
println("init First")
}
public var PROP by DashboardVar(2.0)
}

object Second {
fun initProps() {
println("init Second")
}
public var PROP by DashboardVar(3.0)
}

object Nest {
fun initProps() {
println("init Nested")
Inner.initProps()
}
public var PROP by DashboardVar(4.0)
object Inner {
fun initProps() {
println("init Nest.Inner")
}
public var PROP by DashboardVar(5.0)
}
}
Expand Down
266 changes: 266 additions & 0 deletions src/test/kotlin/tests/StartupTimeTest.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,266 @@
package tests

import org.junit.jupiter.api.Test

import org.team5499.dashboard.DashboardVar

class StartupTimeTest {

object ConstantsNormal {
fun initConstants() {
Nested1.initConstants()
Nested2.initConstants()
Nested3.initConstants()
}
public var CONSTANT_1 = 1.0
public var CONSTANT_2 = 1.0
public var CONSTANT_3 = 1.0
public var CONSTANT_4 = 1.0
public var CONSTANT_5 = 1.0
public var CONSTANT_6 = 1.0
public var CONSTANT_7 = 1.0
public var CONSTANT_8 = 1.0
public var CONSTANT_9 = 1.0
public var CONSTANT_10 = 1.0
public var CONSTANT_11 = 1.0
public var CONSTANT_12 = 1.0
public var CONSTANT_13 = 1.0
public var CONSTANT_14 = 1.0
public var CONSTANT_15 = 1.0
public var CONSTANT_16 = 1.0
public var CONSTANT_17 = 1.0
public var CONSTANT_18 = 1.0
public var CONSTANT_19 = 1.0
public var CONSTANT_20 = 1.0
public var CONSTANT_21 = 1.0
public var CONSTANT_22 = 1.0
public var CONSTANT_23 = 1.0
public var CONSTANT_24 = 1.0
public var CONSTANT_25 = 1.0
object Nested1 {
fun initConstants() {
println("init Nested1")
}
public var CONSTANT_1 = 1.0
public var CONSTANT_2 = 1.0
public var CONSTANT_3 = 1.0
public var CONSTANT_4 = 1.0
public var CONSTANT_5 = 1.0
public var CONSTANT_6 = 1.0
public var CONSTANT_7 = 1.0
public var CONSTANT_8 = 1.0
public var CONSTANT_9 = 1.0
public var CONSTANT_10 = 1.0
public var CONSTANT_11 = 1.0
public var CONSTANT_12 = 1.0
public var CONSTANT_13 = 1.0
public var CONSTANT_14 = 1.0
public var CONSTANT_15 = 1.0
public var CONSTANT_16 = 1.0
public var CONSTANT_17 = 1.0
public var CONSTANT_18 = 1.0
public var CONSTANT_19 = 1.0
public var CONSTANT_20 = 1.0
public var CONSTANT_21 = 1.0
public var CONSTANT_22 = 1.0
public var CONSTANT_23 = 1.0
public var CONSTANT_24 = 1.0
public var CONSTANT_25 = 1.0
}
object Nested2 {
fun initConstants() {
println("init Nested2")
}
public var CONSTANT_1 = 1.0
public var CONSTANT_2 = 1.0
public var CONSTANT_3 = 1.0
public var CONSTANT_4 = 1.0
public var CONSTANT_5 = 1.0
public var CONSTANT_6 = 1.0
public var CONSTANT_7 = 1.0
public var CONSTANT_8 = 1.0
public var CONSTANT_9 = 1.0
public var CONSTANT_10 = 1.0
public var CONSTANT_11 = 1.0
public var CONSTANT_12 = 1.0
public var CONSTANT_13 = 1.0
public var CONSTANT_14 = 1.0
public var CONSTANT_15 = 1.0
public var CONSTANT_16 = 1.0
public var CONSTANT_17 = 1.0
public var CONSTANT_18 = 1.0
public var CONSTANT_19 = 1.0
public var CONSTANT_20 = 1.0
public var CONSTANT_21 = 1.0
public var CONSTANT_22 = 1.0
public var CONSTANT_23 = 1.0
public var CONSTANT_24 = 1.0
public var CONSTANT_25 = 1.0
}
object Nested3 {
fun initConstants() {
println("init Nested3")
}
public var CONSTANT_1 = 1.0
public var CONSTANT_2 = 1.0
public var CONSTANT_3 = 1.0
public var CONSTANT_4 = 1.0
public var CONSTANT_5 = 1.0
public var CONSTANT_6 = 1.0
public var CONSTANT_7 = 1.0
public var CONSTANT_8 = 1.0
public var CONSTANT_9 = 1.0
public var CONSTANT_10 = 1.0
public var CONSTANT_11 = 1.0
public var CONSTANT_12 = 1.0
public var CONSTANT_13 = 1.0
public var CONSTANT_14 = 1.0
public var CONSTANT_15 = 1.0
public var CONSTANT_16 = 1.0
public var CONSTANT_17 = 1.0
public var CONSTANT_18 = 1.0
public var CONSTANT_19 = 1.0
public var CONSTANT_20 = 1.0
public var CONSTANT_21 = 1.0
public var CONSTANT_22 = 1.0
public var CONSTANT_23 = 1.0
public var CONSTANT_24 = 1.0
public var CONSTANT_25 = 1.0
}
}

object ConstantsDashboard {
fun initConstants() {
Nested1.initConstants()
Nested2.initConstants()
Nested3.initConstants()
}
public var CONSTANT_1 by DashboardVar(1.0)
public var CONSTANT_2 by DashboardVar(1.0)
public var CONSTANT_3 by DashboardVar(1.0)
public var CONSTANT_4 by DashboardVar(1.0)
public var CONSTANT_5 by DashboardVar(1.0)
public var CONSTANT_6 by DashboardVar(1.0)
public var CONSTANT_7 by DashboardVar(1.0)
public var CONSTANT_8 by DashboardVar(1.0)
public var CONSTANT_9 by DashboardVar(1.0)
public var CONSTANT_10 by DashboardVar(1.0)
public var CONSTANT_11 by DashboardVar(1.0)
public var CONSTANT_12 by DashboardVar(1.0)
public var CONSTANT_13 by DashboardVar(1.0)
public var CONSTANT_14 by DashboardVar(1.0)
public var CONSTANT_15 by DashboardVar(1.0)
public var CONSTANT_16 by DashboardVar(1.0)
public var CONSTANT_17 by DashboardVar(1.0)
public var CONSTANT_18 by DashboardVar(1.0)
public var CONSTANT_19 by DashboardVar(1.0)
public var CONSTANT_20 by DashboardVar(1.0)
public var CONSTANT_21 by DashboardVar(1.0)
public var CONSTANT_22 by DashboardVar(1.0)
public var CONSTANT_23 by DashboardVar(1.0)
public var CONSTANT_24 by DashboardVar(1.0)
public var CONSTANT_25 by DashboardVar(1.0)
object Nested1 {
fun initConstants() {
println("init Nested1")
}
public var CONSTANT_1 by DashboardVar(1.0)
public var CONSTANT_2 by DashboardVar(1.0)
public var CONSTANT_3 by DashboardVar(1.0)
public var CONSTANT_4 by DashboardVar(1.0)
public var CONSTANT_5 by DashboardVar(1.0)
public var CONSTANT_6 by DashboardVar(1.0)
public var CONSTANT_7 by DashboardVar(1.0)
public var CONSTANT_8 by DashboardVar(1.0)
public var CONSTANT_9 by DashboardVar(1.0)
public var CONSTANT_10 by DashboardVar(1.0)
public var CONSTANT_11 by DashboardVar(1.0)
public var CONSTANT_12 by DashboardVar(1.0)
public var CONSTANT_13 by DashboardVar(1.0)
public var CONSTANT_14 by DashboardVar(1.0)
public var CONSTANT_15 by DashboardVar(1.0)
public var CONSTANT_16 by DashboardVar(1.0)
public var CONSTANT_17 by DashboardVar(1.0)
public var CONSTANT_18 by DashboardVar(1.0)
public var CONSTANT_19 by DashboardVar(1.0)
public var CONSTANT_20 by DashboardVar(1.0)
public var CONSTANT_21 by DashboardVar(1.0)
public var CONSTANT_22 by DashboardVar(1.0)
public var CONSTANT_23 by DashboardVar(1.0)
public var CONSTANT_24 by DashboardVar(1.0)
public var CONSTANT_25 by DashboardVar(1.0)
}
object Nested2 {
fun initConstants() {
println("init Nested2")
}
public var CONSTANT_1 by DashboardVar(1.0)
public var CONSTANT_2 by DashboardVar(1.0)
public var CONSTANT_3 by DashboardVar(1.0)
public var CONSTANT_4 by DashboardVar(1.0)
public var CONSTANT_5 by DashboardVar(1.0)
public var CONSTANT_6 by DashboardVar(1.0)
public var CONSTANT_7 by DashboardVar(1.0)
public var CONSTANT_8 by DashboardVar(1.0)
public var CONSTANT_9 by DashboardVar(1.0)
public var CONSTANT_10 by DashboardVar(1.0)
public var CONSTANT_11 by DashboardVar(1.0)
public var CONSTANT_12 by DashboardVar(1.0)
public var CONSTANT_13 by DashboardVar(1.0)
public var CONSTANT_14 by DashboardVar(1.0)
public var CONSTANT_15 by DashboardVar(1.0)
public var CONSTANT_16 by DashboardVar(1.0)
public var CONSTANT_17 by DashboardVar(1.0)
public var CONSTANT_18 by DashboardVar(1.0)
public var CONSTANT_19 by DashboardVar(1.0)
public var CONSTANT_20 by DashboardVar(1.0)
public var CONSTANT_21 by DashboardVar(1.0)
public var CONSTANT_22 by DashboardVar(1.0)
public var CONSTANT_23 by DashboardVar(1.0)
public var CONSTANT_24 by DashboardVar(1.0)
public var CONSTANT_25 by DashboardVar(1.0)
}
object Nested3 {
fun initConstants() {
println("init Nested3")
}
public var CONSTANT_1 by DashboardVar(1.0)
public var CONSTANT_2 by DashboardVar(1.0)
public var CONSTANT_3 by DashboardVar(1.0)
public var CONSTANT_4 by DashboardVar(1.0)
public var CONSTANT_5 by DashboardVar(1.0)
public var CONSTANT_6 by DashboardVar(1.0)
public var CONSTANT_7 by DashboardVar(1.0)
public var CONSTANT_8 by DashboardVar(1.0)
public var CONSTANT_9 by DashboardVar(1.0)
public var CONSTANT_10 by DashboardVar(1.0)
public var CONSTANT_11 by DashboardVar(1.0)
public var CONSTANT_12 by DashboardVar(1.0)
public var CONSTANT_13 by DashboardVar(1.0)
public var CONSTANT_14 by DashboardVar(1.0)
public var CONSTANT_15 by DashboardVar(1.0)
public var CONSTANT_16 by DashboardVar(1.0)
public var CONSTANT_17 by DashboardVar(1.0)
public var CONSTANT_18 by DashboardVar(1.0)
public var CONSTANT_19 by DashboardVar(1.0)
public var CONSTANT_20 by DashboardVar(1.0)
public var CONSTANT_21 by DashboardVar(1.0)
public var CONSTANT_22 by DashboardVar(1.0)
public var CONSTANT_23 by DashboardVar(1.0)
public var CONSTANT_24 by DashboardVar(1.0)
public var CONSTANT_25 by DashboardVar(1.0)
}
}

@Test
fun classInitTest() {
val dashStartTime = System.nanoTime()
ConstantsDashboard.initConstants()
val dashStopTime = System.nanoTime()
println("Dashboard delegates: ${dashStopTime - dashStartTime}")
val normalStartTime = System.nanoTime()
ConstantsDashboard.initConstants()
val normalStopTime = System.nanoTime()
println("Normal properties: ${normalStopTime - normalStartTime}")
}
}
1 change: 1 addition & 0 deletions src/test/kotlin/tests/WebdriverTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class WebdriverTest {
@JvmStatic
fun init() {
Dashboard.start(this, "webdriverConfig.json")
Dashboard.waitForInitialization()
driver = WebdriverSetup.getDriver()
actions = Actions(driver)
}
Expand Down

0 comments on commit 79102e1

Please sign in to comment.