Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New: Gson added to operate with Graph stored. #45

Merged
merged 2 commits into from
Dec 11, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ repositories {

dependencies {
implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlinVersion")
implementation("org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion")
implementation("com.google.code.gson:gson:2.8.6")

testImplementation("org.mockito:mockito-core:2.+")
testImplementation("org.testng:testng-6.14.3")
}

Expand Down
2 changes: 2 additions & 0 deletions degitx-simulator.iml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
<sourceFolder url="file://$MODULE_DIR$/src/main" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/lib" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/main/resources" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/test/resources" type="java-test-resource" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
Expand All @@ -23,5 +24,6 @@
<SOURCES />
</library>
</orderEntry>
<orderEntry type="library" name="gson-2.8.6" level="project" />
</component>
</module>
39 changes: 39 additions & 0 deletions src/main/com/cqfn/degitx/simulator/data/GraphData.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package com.cqfn.degitx.simulator.data

/**
* Data class to store, load and save graph structure.
*/
data class GraphData(
val graph: Graph
)

data class Graph(
val edges: List<Edge>,
val nodes: List<Node>
)

data class Edge(
val head: String,
val tail: String
)

data class Node(
val hardware: Hardware,
val id: String,
val state: String
)

data class Hardware(
val net: Net,
val storage: Storage
)

data class Net(
val addr: String,
val throughput: Int
)

data class Storage(
val r: Int,
val w: Int
)
2 changes: 1 addition & 1 deletion src/test/com/cqfn/degitx/simulator/RequestPathTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,4 @@ class RequestPathTest {
graph.nodes[1].run((rq))
Assert.assertEquals(rq.timespent, 1000)
}
}
}
26 changes: 26 additions & 0 deletions src/test/com/cqfn/degitx/simulator/data/GraphDataTest.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.cqfn.degitx.simulator.data

import com.cqfn.degitx.simulator.GraphGenerator
import com.google.gson.Gson
import org.testng.annotations.Test
import java.io.File

class GraphDataTest {

var graph = GraphGenerator()

@Test
fun testTestToString() {
val resourceName = "src/test/resources/testGraph.json"
val content = File(resourceName).readText(Charsets.UTF_8)
var grData = Gson().fromJson(content, GraphData::class.java)
println(grData.graph)
}

@Test
fun witeStaticGraph() {
graph.generate(GraphGenerator.Settings())
var grData = Gson().toJson(graph)
println(grData)
}
}
23 changes: 23 additions & 0 deletions src/test/resources/testGraph.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"graph": {"nodes":[
{
"id": "node1",
"state": "A",
"hw": {
"storage": {
"w": 10,
"r": 1000
},
"net": {
"addr": "address",
"throughput": 20
}
}
}
],"edges":[{
"head": "node2",
"tail": "node1"
}
]
}
}