-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix InventoryItem name and alias definition
- Loading branch information
Showing
18 changed files
with
132 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
js7-data/shared/src/test/scala/js7/data/subagent/SubagentBundleIdTest.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package js7.data.subagent | ||
|
||
import js7.base.test.OurTestSuite | ||
|
||
final class SubagentBundleIdTest extends OurTestSuite: | ||
|
||
"SubagentBundleId" in: | ||
assert(SubagentBundleId("BUNDLE").toString == "SubagentBundle:BUNDLE") | ||
assert(SubagentBundleId.pathTypeName == "SubagentBundle") | ||
assert(SubagentBundleId.pathTypeNames == Seq("SubagentBundle", "SubagentSelection")) | ||
assert(SubagentBundleId.itemTypeName == "SubagentBundle") |
104 changes: 72 additions & 32 deletions
104
js7-data/shared/src/test/scala/js7/data/subagent/SubagentBundleTest.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,44 +1,84 @@ | ||
package js7.data.subagent | ||
|
||
import js7.base.circeutils.CirceUtils.* | ||
import js7.base.circeutils.typed.TypedJsonCodec | ||
import js7.base.test.OurTestSuite | ||
import js7.data.controller.ControllerState.inventoryItemJsonCodec | ||
import js7.data.item.InventoryItem | ||
import js7.data.agent.AgentPath | ||
import js7.data.controller.ControllerState | ||
import js7.data.controller.ControllerState.{inventoryItemJsonCodec, inventoryItemKeyJsonCodec} | ||
import js7.data.item.BasicItemEvent.ItemAttached | ||
import js7.data.item.{BasicItemEvent, InventoryItem, InventoryItemKey} | ||
import js7.data.value.expression.Expression.NumericConstant | ||
import js7.data.value.expression.ExpressionParser.expr | ||
import js7.tester.CirceJsonTester.{testJson, testJsonDecoder} | ||
|
||
final class SubagentBundleTest extends OurTestSuite: | ||
|
||
"JSON" in: | ||
testJson[InventoryItem]( | ||
SubagentBundle( | ||
"JSON" - { | ||
"SubagentBundle" in: | ||
testJson[InventoryItem]( | ||
SubagentBundle( | ||
SubagentBundleId("BUNDLE"), | ||
Map( | ||
SubagentId("A-SUBAGENT") -> NumericConstant(1), | ||
SubagentId("B-SUBAGENT") -> expr("min(100, (1 / $cpuLoad) ? 100)"))), | ||
json"""{ | ||
"TYPE": "SubagentBundle", | ||
"id": "BUNDLE", | ||
"subagentToPriority": { | ||
"A-SUBAGENT": 1, | ||
"B-SUBAGENT": "min(100, (1 / $$cpuLoad) ? 100)" | ||
} | ||
}""") | ||
|
||
"InventoryItemKey" in: | ||
testJson[InventoryItemKey]( | ||
SubagentBundleId("BUNDLE"), | ||
Map( | ||
SubagentId("A-SUBAGENT") -> NumericConstant(1), | ||
SubagentId("B-SUBAGENT") -> expr("min(100, (1 / $cpuLoad) ? 100)"))), | ||
json"""{ | ||
"TYPE": "SubagentBundle", | ||
"id": "BUNDLE", | ||
"subagentToPriority": { | ||
"A-SUBAGENT": 1, | ||
"B-SUBAGENT": "min(100, (1 / $$cpuLoad) ? 100)" | ||
} | ||
}""") | ||
|
||
"JSON until v2.7.1" in: | ||
// COMPATIBLE with v2.7.1 | ||
testJsonDecoder[InventoryItem]( | ||
SubagentBundle( | ||
json""" "SubagentBundle:BUNDLE" """) | ||
|
||
"ItemAttached" in: | ||
given TypedJsonCodec[BasicItemEvent] = BasicItemEvent.jsonCodec(ControllerState) | ||
|
||
testJson[BasicItemEvent]( | ||
ItemAttached(SubagentBundleId("BUNDLE"), None, AgentPath("AGENT")), | ||
json"""{ | ||
"TYPE": "ItemAttached", | ||
"key": "SubagentBundle:BUNDLE", | ||
"delegateId": "Agent:AGENT" | ||
}""") | ||
} | ||
|
||
"JSON until v2.7.1" - { | ||
"InventoryItem" in: | ||
// COMPATIBLE with v2.7.1 | ||
testJsonDecoder[InventoryItem]( | ||
SubagentBundle( | ||
SubagentBundleId("BUNDLE"), | ||
Map( | ||
SubagentId("A-SUBAGENT") -> NumericConstant(1), | ||
SubagentId("B-SUBAGENT") -> expr("min(100, (1 / $cpuLoad) ? 100)"))), | ||
json"""{ | ||
"TYPE": "SubagentSelection", | ||
"id": "BUNDLE", | ||
"subagentToPriority": { | ||
"A-SUBAGENT": 1, | ||
"B-SUBAGENT": "min(100, (1 / $$cpuLoad) ? 100)" | ||
} | ||
}""") | ||
|
||
"InventoryItemKey" in: | ||
testJsonDecoder[InventoryItemKey]( | ||
SubagentBundleId("BUNDLE"), | ||
Map( | ||
SubagentId("A-SUBAGENT") -> NumericConstant(1), | ||
SubagentId("B-SUBAGENT") -> expr("min(100, (1 / $cpuLoad) ? 100)"))), | ||
json"""{ | ||
"TYPE": "SubagentSelection", | ||
"id": "BUNDLE", | ||
"subagentToPriority": { | ||
"A-SUBAGENT": 1, | ||
"B-SUBAGENT": "min(100, (1 / $$cpuLoad) ? 100)" | ||
} | ||
}""") | ||
json""" "SubagentSelection:BUNDLE" """) | ||
|
||
"ItemAttached" in: | ||
given TypedJsonCodec[BasicItemEvent] = BasicItemEvent.jsonCodec(ControllerState) | ||
|
||
testJsonDecoder[BasicItemEvent]( | ||
ItemAttached(SubagentBundleId("BUNDLE"), None, AgentPath("AGENT")), | ||
json"""{ | ||
"TYPE": "ItemAttached", | ||
"key": "SubagentSelection:BUNDLE", | ||
"delegateId": "Agent:AGENT" | ||
}""") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters