Skip to content

Commit

Permalink
[Java] Sync the improvements from kotlin-matter-controller (#29716)
Browse files Browse the repository at this point in the history
* Sync the improvements from kotlin-matter-controller

* Increase the timeout value to 3s
  • Loading branch information
yufengwangca authored and pull[bot] committed Feb 14, 2024
1 parent 3dc7f3f commit 1056516
Show file tree
Hide file tree
Showing 15 changed files with 38 additions and 49 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/java-tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ jobs:
--app-args "--discriminator 3840 --interface-id -1" \
--tool-path out/linux-x64-java-matter-controller \
--tool-cluster "im" \
--tool-args "onnetwork-long-im-read --nodeid 1 --setup-pin-code 20202021 --discriminator 3840 -t 1000" \
--tool-args "onnetwork-long-im-read --nodeid 1 --setup-pin-code 20202021 --discriminator 3840 -t 3000" \
--factoryreset \
'
- name: Run IM Write Test
Expand All @@ -162,7 +162,7 @@ jobs:
--app-args "--discriminator 3840 --interface-id -1" \
--tool-path out/linux-x64-java-matter-controller \
--tool-cluster "im" \
--tool-args "onnetwork-long-im-subscribe --nodeid 1 --setup-pin-code 20202021 --discriminator 3840 -t 1000" \
--tool-args "onnetwork-long-im-subscribe --nodeid 1 --setup-pin-code 20202021 --discriminator 3840 -t 3000" \
--factoryreset \
'
- name: Run Pairing AlreadyDiscovered Test
Expand Down Expand Up @@ -229,7 +229,7 @@ jobs:
--app-args "--discriminator 3840 --interface-id -1" \
--tool-path out/linux-x64-kotlin-matter-controller \
--tool-cluster "im" \
--tool-args "onnetwork-long-im-read --nodeid 1 --setup-pin-code 20202021 --discriminator 3840 -t 1000" \
--tool-args "onnetwork-long-im-read --nodeid 1 --setup-pin-code 20202021 --discriminator 3840 -t 3000" \
--factoryreset \
'
- name: Run Kotlin IM Write Test
Expand All @@ -251,7 +251,7 @@ jobs:
--app-args "--discriminator 3840 --interface-id -1" \
--tool-path out/linux-x64-kotlin-matter-controller \
--tool-cluster "im" \
--tool-args "onnetwork-long-im-subscribe --nodeid 1 --setup-pin-code 20202021 --discriminator 3840 -t 1000" \
--tool-args "onnetwork-long-im-subscribe --nodeid 1 --setup-pin-code 20202021 --discriminator 3840 -t 3000" \
--factoryreset \
'
- name: Uploading core files
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,6 @@
* limitations under the License.
*/

/**
* @file
* Project configuration for Matter Controller.
*
*/
#ifndef CHIPPROJECTCONFIG_H
#define CHIPPROJECTCONFIG_H

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ class Argument {
isValidArgument =
try {
val ipAddress = this.value as IPAddress
ipAddress.setAddress(InetAddress.getByName(value))
ipAddress.address = InetAddress.getByName(value)
true
} catch (e: UnknownHostException) {
false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@ package com.matter.controller.commands.common

/**
* Credentials Issuer which contains all credential information of the issuer of the command, such
* as operational credentials for a given fabric, the DAC verifier of the commisioner, etc ..
* as operational credentials for a given fabric, the DAC verifier of the commissioner, etc ..
*/
class CredentialsIssuer
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,8 @@ import java.util.logging.Logger
*/
class FutureResult {
private var realResult: RealResult? = null
private var timeoutMs: Long = 0
private val logger = Logger.getLogger(FutureResult::class.java.name)
private val lock = Object()

fun setTimeoutMs(timeoutMs: Long) {
this.timeoutMs = timeoutMs
}
var timeoutMs: Long = 0

fun setRealResult(realResult: RealResult) {
synchronized(lock) {
Expand All @@ -52,17 +47,21 @@ class FutureResult {
val start = System.currentTimeMillis()
synchronized(lock) {
while (realResult == null) {
val remainingTime = timeoutMs - (System.currentTimeMillis() - start)
if (remainingTime <= 0) {
throw TimeoutException("Timeout!")
}

try {
if (System.currentTimeMillis() > start + timeoutMs) {
throw TimeoutException("Timeout!")
}
lock.wait()
lock.wait(remainingTime)
} catch (e: InterruptedException) {
logger.log(Level.INFO, "Wait Result failed with exception: " + e.message)
}
}
if (realResult?.result == false) {
logger.log(Level.INFO, "Error: ${realResult?.error}")

val errorResult = realResult as? RealResult.Error
if (errorResult != null) {
logger.log(Level.INFO, "Error: ${errorResult.error}")
throw TimeoutException("Received failure test result")
}
}
Expand All @@ -71,4 +70,8 @@ class FutureResult {
fun clear() {
synchronized(lock) { realResult = null }
}

companion object {
private val logger = Logger.getLogger(FutureResult::class.java.name)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,7 @@ package com.matter.controller.commands.common

import java.net.InetAddress

class IPAddress(private var address: InetAddress) {
fun setAddress(address: InetAddress) {
this.address = address
}

fun getHostAddress(): String {
return address.hostAddress
}

class IPAddress(var address: InetAddress) {
override fun toString(): String {
return address.toString()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ abstract class MatterCommand(
}

fun waitCompleteMs(timeoutMs: Long) {
futureResult.setTimeoutMs(timeoutMs)
futureResult.timeoutMs = timeoutMs
futureResult.waitResult()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,24 +19,23 @@
package com.matter.controller.commands.common

/**
* Implements a Result where an error string is associated with its failure state.
* Represents a result that can either indicate success or failure with an associated error message.
*
* <p>A `Result` is just a booean of true/false that is exposed via `getResult`. This class will
* contain either a `true` value for `Success` or a `false` value in which case the failure will
* also have an error string explaining the reason of the failure associated with it.
* In the context of RealResult, success is represented by [Success] and failure by [Error]. When
* there is an error, an error message explains the reason for the failure.
*/
class RealResult(val result: Boolean, val error: String?) {
constructor() : this(true, null)
sealed class RealResult {
data class Error(val error: String) : RealResult()

constructor(error: String?) : this(false, error)
object Success : RealResult()

companion object {
fun success(): RealResult {
return RealResult()
return Success
}

fun error(error: String?): RealResult {
return RealResult(error)
return error?.let { Error(it) } ?: Success
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class PairAddressPaseCommand(controller: ChipDeviceController, credsIssue: Crede
currentCommissioner()
.establishPaseConnection(
getNodeId(),
getRemoteAddr().getHostAddress(),
getRemoteAddr().address.hostAddress,
getRemotePort(),
getSetupPINCode()
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class PairAlreadyDiscoveredCommand(
currentCommissioner()
.pairDeviceWithAddress(
getNodeId(),
getRemoteAddr().getHostAddress(),
getRemoteAddr().address.hostAddress,
getRemotePort(),
getDiscriminator(),
getSetupPINCode(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class PairOnNetworkLongCommand(
currentCommissioner()
.pairDeviceWithAddress(
getNodeId(),
getRemoteAddr().getHostAddress(),
getRemoteAddr().address.hostAddress,
MATTER_PORT,
getDiscriminator(),
getSetupPINCode(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ class PairOnNetworkLongImInvokeCommand(
currentCommissioner()
.pairDeviceWithAddress(
getNodeId(),
getRemoteAddr().getHostAddress(),
getRemoteAddr().address.hostAddress,
MATTER_PORT,
getDiscriminator(),
getSetupPINCode(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ class PairOnNetworkLongImReadCommand(
currentCommissioner()
.pairDeviceWithAddress(
getNodeId(),
getRemoteAddr().getHostAddress(),
getRemoteAddr().address.hostAddress,
MATTER_PORT,
getDiscriminator(),
getSetupPINCode(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ class PairOnNetworkLongImSubscribeCommand(
currentCommissioner()
.pairDeviceWithAddress(
getNodeId(),
getRemoteAddr().getHostAddress(),
getRemoteAddr().address.hostAddress,
MATTER_PORT,
getDiscriminator(),
getSetupPINCode(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ class PairOnNetworkLongImWriteCommand(
currentCommissioner()
.pairDeviceWithAddress(
getNodeId(),
getRemoteAddr().getHostAddress(),
getRemoteAddr().address.hostAddress,
MATTER_PORT,
getDiscriminator(),
getSetupPINCode(),
Expand Down

0 comments on commit 1056516

Please sign in to comment.