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.
Support directories and add tests #19
- Store Neo4J databases in a directory. - Remove execution counter to simplify code. - Reuse the sutState and action messages when creating identifiers. - Simplify tests and reuse them for Neo4J.
- Loading branch information
Showing
26 changed files
with
386 additions
and
381 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
2 changes: 1 addition & 1 deletion
2
src/main/scala/de/retest/guistatemachine/api/GuiStateMachineSerializer.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
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
61 changes: 35 additions & 26 deletions
61
src/main/scala/de/retest/guistatemachine/api/neo4j/GuiStateMachineApiNeo4J.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,42 +1,51 @@ | ||
package de.retest.guistatemachine.api.neo4j | ||
|
||
import java.io.File | ||
import java.nio.file.Paths | ||
|
||
import com.typesafe.scalalogging.Logger | ||
import de.retest.guistatemachine.api.{GuiStateMachine, GuiStateMachineApi} | ||
import org.apache.commons.io.FileUtils | ||
|
||
import scala.collection.concurrent.TrieMap | ||
|
||
class GuiStateMachineApiNeo4J extends GuiStateMachineApi { | ||
class GuiStateMachineApiNeo4J(directory: String) extends GuiStateMachineApi { | ||
private val logger = Logger[GuiStateMachineApiNeo4J] | ||
private val stateMachines = TrieMap[String, GuiStateMachineNeo4J]() | ||
// TODO #19 Load existing state machines based on Neo4J graph databases. | ||
|
||
override def createStateMachine(name: String): GuiStateMachine = { | ||
val uri = getUri(name) | ||
Neo4jSessionFactory.getSessionFactoryEmbedded(uri) | ||
logger.info("Created new graph DB in {}.", uri) | ||
override def createStateMachine(name: String): GuiStateMachine = | ||
if (isDirectory(name)) { | ||
throw new RuntimeException(s"State machine $name does already exist.") | ||
} else { | ||
val uri = getUri(name) | ||
Neo4jSessionFactory.getSessionFactoryEmbedded(uri) | ||
logger.info("Created new graph DB in {}.", uri) | ||
|
||
val guiStateMachine = new GuiStateMachineNeo4J(uri) | ||
stateMachines += (name -> guiStateMachine) | ||
guiStateMachine | ||
} | ||
new GuiStateMachineNeo4J(uri) | ||
} | ||
|
||
override def removeStateMachine(name: String): Boolean = stateMachines.remove(name) match { | ||
case Some(stateMachine) => | ||
// TODO #19 Should we remove the state machine from the disk? | ||
stateMachine.clear() | ||
val uri = getUri(name) | ||
Neo4jSessionFactory.getSessionFactoryEmbedded(uri).close() | ||
override def removeStateMachine(name: String): Boolean = | ||
if (isDirectory(name)) { | ||
val file = getFile(name) | ||
logger.info("Deleting state machine in {}.", file) | ||
FileUtils.deleteDirectory(file) | ||
true | ||
case None => false | ||
} | ||
|
||
override def getStateMachine(name: String): Option[GuiStateMachine] = stateMachines.get(name) | ||
} else { | ||
false | ||
} | ||
|
||
override def clear(): Unit = stateMachines.keySet foreach { name => // TODO #19 keys can be modified concurrently. So we might not remove all state machines? | ||
removeStateMachine(name) | ||
override def getStateMachine(name: String): Option[GuiStateMachine] = | ||
if (isDirectory(name)) { | ||
val uri = getUri(name) | ||
Some(new GuiStateMachineNeo4J(uri)) | ||
} else { | ||
None | ||
} | ||
|
||
override def clear(): Unit = { | ||
logger.info("Deleting all state machines in {}.", directory) | ||
FileUtils.deleteDirectory(getStorageDirectory()) | ||
} | ||
|
||
private def getUri(name: String): String = new File(name).toURI.toString | ||
private def getStorageDirectory(): File = new File(directory) | ||
private def isDirectory(name: String): Boolean = getFile(name).isDirectory | ||
private def getFile(name: String): File = new File(Paths.get(directory, name).toAbsolutePath.toString) | ||
private def getUri(name: String): String = getFile(name).toURI.toString | ||
} |
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
3 changes: 2 additions & 1 deletion
3
.../impl/serialization/GraphActionEdge.scala → ...e/api/serialization/GraphActionEdge.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
2 changes: 1 addition & 1 deletion
2
...impl/serialization/GraphicsProvider.scala → .../api/serialization/GraphicsProvider.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
3 changes: 2 additions & 1 deletion
3
...ization/GuiStateMachinGMLSerializer.scala → ...ization/GuiStateMachinGMLSerializer.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
2 changes: 1 addition & 1 deletion
2
...teMachineJavaObjectStreamSerializer.scala → ...teMachineJavaObjectStreamSerializer.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
Oops, something went wrong.