This repository has been archived by the owner on Mar 12, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Swagger support for REST, execution counters for actions, persistence…
… methods #1 #7 #9 - Besides, update some scalastyle rules. - Move all sbt plugins to one file. - Do some refactoring, so we only used immutable data structures. - Add type ActionTransitions which stores the execution times. - Initial persistence methods. - Add initial Swagger support for the REST service.
- Loading branch information
Showing
42 changed files
with
307 additions
and
144 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 was deleted.
Oops, something went wrong.
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,10 @@ | ||
// to create a standalone JAR file with all dependencies | ||
addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "0.14.6") | ||
// code formatting | ||
addSbtPlugin("com.lucidchart" % "sbt-scalafmt" % "1.15") | ||
// for signed releases | ||
addSbtPlugin("com.jsuereth" % "sbt-pgp" % "1.1.1") | ||
addSbtPlugin("com.typesafe.sbteclipse" % "sbteclipse-plugin" % "5.2.4") | ||
addSbtPlugin("com.github.gseitz" % "sbt-release" % "1.0.10") | ||
addSbtPlugin("org.scalastyle" %% "scalastyle-sbt-plugin" % "1.0.0") | ||
addSbtPlugin("org.scoverage" % "sbt-scoverage" % "1.5.1") |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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
src/main/scala/de/retest/guistatemachine/api/ActionTransitions.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 de.retest.guistatemachine.api | ||
|
||
/** | ||
* Represents transitions for one single symbol which is represented by an [[Action]] to a number of states. | ||
* The corresponding symbol is not stored in this class but in the [[State]] from which the transitions are started. | ||
* | ||
* @param to The states which the transitions lead to. Since it is a NFA, there can be multiple states for the same symbol. | ||
* @param executionCounter The number of times all transitions for the action have been executed from the corresponding state. | ||
* It does not matter to which state. In the legacy code this was stored as `StateGraph.executionCounter`. | ||
*/ | ||
case class ActionTransitions(to: Set[State], executionCounter: Int) |
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
37 changes: 24 additions & 13 deletions
37
src/main/scala/de/retest/guistatemachine/api/impl/GuiStateMachineImpl.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,55 @@ | ||
package de.retest.guistatemachine.api.impl | ||
|
||
import de.retest.guistatemachine.api.{Action, Descriptors, GuiStateMachine, State} | ||
|
||
import scala.collection.mutable.HashMap | ||
import scala.collection.mutable.HashSet | ||
import scala.collection.immutable.{HashMap, HashSet} | ||
|
||
class GuiStateMachineImpl extends GuiStateMachine { | ||
val states = new HashMap[Descriptors, State] | ||
var states = new HashMap[Descriptors, State] | ||
|
||
/** | ||
* In the legacy code we had `getAllNeverExploredActions` which had to collect them from all states and make sure they were never executed. | ||
* Storing them directly in a set improves efficiency. | ||
*/ | ||
val allNeverExploredActions = new HashSet[Action] | ||
var allNeverExploredActions = new HashSet[Action] | ||
|
||
/** | ||
* The legacy code stored execution counters for every action. | ||
*/ | ||
val allExploredActions = new HashSet[Action] | ||
var allExploredActions = new HashSet[Action] | ||
|
||
/** | ||
* `actionExecutionCounter` from the legacy code. | ||
* Stores the total number of executions per action. | ||
*/ | ||
var actionExecutionTimes = new HashMap[Action, Int] | ||
|
||
override def getState(descriptors: Descriptors, neverExploredActions: Set[Action]): State = { | ||
if (states.contains(descriptors)) { | ||
states(descriptors) | ||
} else { | ||
allNeverExploredActions ++= (neverExploredActions -- allExploredActions) | ||
allNeverExploredActions = allNeverExploredActions ++ (neverExploredActions -- allExploredActions) | ||
val s = new StateImpl(descriptors, neverExploredActions) | ||
states += (descriptors -> s) | ||
states = states + (descriptors -> s) | ||
s | ||
} | ||
} | ||
|
||
override def executeAction(from: State, a: Action, descriptors: Descriptors, neverExploredActions: Set[Action]): State = { | ||
val to = getState(descriptors, neverExploredActions) | ||
allExploredActions += a | ||
allNeverExploredActions -= a | ||
allExploredActions = allExploredActions + a | ||
allNeverExploredActions = allNeverExploredActions - a | ||
val old = actionExecutionTimes.get(a) | ||
old match { | ||
case Some(o) => actionExecutionTimes = actionExecutionTimes + (a -> (o + 1)) | ||
case None => actionExecutionTimes = actionExecutionTimes + (a -> 1) | ||
} | ||
from.addTransition(a, to) | ||
to | ||
} | ||
|
||
override def getAllNeverExploredActions: scala.collection.mutable.Set[Action] = allNeverExploredActions | ||
override def getAllNeverExploredActions: Set[Action] = allNeverExploredActions | ||
|
||
override def getAllExploredActions: Set[Action] = allExploredActions | ||
|
||
override def getAllExploredActions: scala.collection.mutable.Set[Action] = allExploredActions | ||
} | ||
override def getActionExecutionTimes: Map[Action, Int] = actionExecutionTimes | ||
} |
34 changes: 21 additions & 13 deletions
34
src/main/scala/de/retest/guistatemachine/api/impl/StateImpl.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,28 +1,36 @@ | ||
package de.retest.guistatemachine.api.impl | ||
|
||
import de.retest.guistatemachine.api.{Action, Descriptors, State} | ||
import de.retest.guistatemachine.api.{Action, ActionTransitions, Descriptors, State} | ||
|
||
import scala.collection.immutable.{HashMap, HashSet} | ||
import scala.collection.immutable.HashMap | ||
|
||
class StateImpl(val descriptors: Descriptors, var neverExploredActions: Set[Action]) extends State { | ||
class StateImpl(descriptors: Descriptors, var neverExploredActions: Set[Action]) extends State { | ||
|
||
/** | ||
* TODO #4 Currently, there is no MultiMap trait for immutable maps in the Scala standard library. | ||
* The legacy code used `AmbigueState` here which was more complicated than just a multi map. | ||
*/ | ||
var transitions = new HashMap[Action, Set[State]] | ||
var transitions = new HashMap[Action, ActionTransitions] | ||
|
||
override def getDescriptors: Descriptors = descriptors | ||
override def getNeverExploredActions: Set[Action] = neverExploredActions | ||
override def getTransitions: Map[Action, Set[State]] = transitions | ||
override def getTransitions: Map[Action, ActionTransitions] = transitions | ||
|
||
private[api] override def addTransition(a: Action, to: State): Unit = { | ||
if (!transitions.contains(a)) { | ||
transitions = transitions + (a -> HashSet(to)) | ||
// In the legacy code this is done in `increaseTimesExecuted`. | ||
neverExploredActions = neverExploredActions - a | ||
} else { | ||
transitions = transitions + (a -> (transitions(a) + to)) | ||
private[api] override def addTransition(a: Action, to: State): Int = { | ||
val old = transitions.get(a) | ||
old match { | ||
case Some(o) => { | ||
val updated = ActionTransitions(o.to + to, o.executionCounter + 1) | ||
transitions = transitions + (a -> updated) | ||
updated.executionCounter | ||
} | ||
|
||
case None => { | ||
transitions += (a -> ActionTransitions(Set(to), 1)) | ||
// In the legacy code this is done in `increaseTimesExecuted`. | ||
neverExploredActions = neverExploredActions - a | ||
1 | ||
} | ||
} | ||
} | ||
} | ||
} |
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
Oops, something went wrong.