You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nlpcraft.apache.org by se...@apache.org on 2020/09/22 12:40:07 UTC
[incubator-nlpcraft] branch NLPCRAFT-135 updated: WIP.
This is an automated email from the ASF dual-hosted git repository.
sergeykamov pushed a commit to branch NLPCRAFT-135
in repository https://gitbox.apache.org/repos/asf/incubator-nlpcraft.git
The following commit(s) were added to refs/heads/NLPCRAFT-135 by this push:
new 500e15d WIP.
500e15d is described below
commit 500e15d982134d5d09add78cc7c74120e7baeed7
Author: Sergey Kamov <se...@apache.org>
AuthorDate: Tue Sep 22 15:39:59 2020 +0300
WIP.
---
.../model/conversation/NCTimeoutSpec.scala | 62 ++++++++++++++++------
1 file changed, 47 insertions(+), 15 deletions(-)
diff --git a/nlpcraft/src/test/scala/org/apache/nlpcraft/model/conversation/NCTimeoutSpec.scala b/nlpcraft/src/test/scala/org/apache/nlpcraft/model/conversation/NCTimeoutSpec.scala
index 1ae4879..2885567 100644
--- a/nlpcraft/src/test/scala/org/apache/nlpcraft/model/conversation/NCTimeoutSpec.scala
+++ b/nlpcraft/src/test/scala/org/apache/nlpcraft/model/conversation/NCTimeoutSpec.scala
@@ -27,42 +27,67 @@ import org.apache.nlpcraft.{NCTestContext, NCTestEnvironment}
import org.junit.jupiter.api.Assertions._
import org.junit.jupiter.api.Test
+object NCTimeoutSpecModel {
+ final val TIMEOUT = 2000
+}
+
+import org.apache.nlpcraft.model.conversation.NCTimeoutSpecModel._
+
class NCTimeoutSpecModel extends NCModel {
- private var cnt = 0
+ private var step = 0
+ private var saveData: util.Map[String, AnyRef] = _
override def getId: String = this.getClass.getSimpleName
+
override def getName: String = this.getClass.getSimpleName
+
override def getVersion: String = "1.0.0"
- override def getConversationTimeout: Long = 2000
+ override def getConversationTimeout: Long = TIMEOUT
override def getElements: util.Set[NCElement] =
Collections.singleton(
new NCElement {
override def getId: String = "test"
+
override def getSynonyms: util.List[String] = Collections.singletonList("test")
}
)
@NCIntent("intent=req conv=true term={id == 'test'}")
def onMatch(ctx: NCIntentMatch): NCResult = {
- ctx.getContext.getConversation.getData.put("key", "value")
+ val conv = ctx.getContext.getConversation
- assertTrue(ctx.getContext.getConversation.getData.containsKey("key"))
+ step match {
+ case 0 ⇒
+ assertTrue(conv.getData.isEmpty)
+ assertTrue(conv.getDialogFlow.isEmpty)
- if (cnt == 0)
- assertTrue(ctx.getContext.getConversation.getDialogFlow.isEmpty)
- else
- assertFalse(ctx.getContext.getConversation.getDialogFlow.isEmpty)
+ conv.getData.put("key", "value")
- Thread.sleep(getConversationTimeout + 1000)
+ saveData = conv.getData
+ case 1 ⇒
+ assertFalse(conv.getData.isEmpty)
+ assertFalse(saveData.isEmpty)
- assertTrue(ctx.getContext.getConversation.getData.isEmpty)
- assertTrue(ctx.getContext.getConversation.getDialogFlow.isEmpty)
+ assertFalse(conv.getDialogFlow.isEmpty)
- val msg = s"OK-$cnt"
+ assertTrue(conv.getData.containsKey("key"))
+ case 2 ⇒
+ assertTrue(conv.getData.isEmpty)
+ assertTrue(saveData.isEmpty)
- cnt = cnt + 1
+ assertTrue(conv.getDialogFlow.isEmpty)
+ case 3 ⇒
+ assertTrue(conv.getData.isEmpty)
+ assertFalse(conv.getDialogFlow.isEmpty)
+
+ case _ ⇒ require(false)
+ }
+
+ val msg = s"OK-$step"
+
+ step = step + 1
NCResult.json(msg)
}
@@ -77,7 +102,14 @@ class NCTimeoutSpec extends NCTestContext {
@throws[NCException]
@throws[IOException]
private[conversation] def test(): Unit = {
- assertTrue(getClient.ask("test").isOk)
- assertTrue(getClient.ask("test").isOk)
+ def ask(): Unit = assertTrue(getClient.ask("test").isOk)
+
+ ask()
+ ask()
+
+ Thread.sleep(TIMEOUT + 1000)
+
+ ask()
+ ask()
}
}