[GEARPUMP-288] Skip getAcyclicCopy on acyclic graph

Author: manuzhang <owenzhang1990@gmail.com>

Closes #166 from manuzhang/GEARPUMP-288.
diff --git a/core/src/main/scala/org/apache/gearpump/util/Graph.scala b/core/src/main/scala/org/apache/gearpump/util/Graph.scala
index 2ea552c..609b133 100644
--- a/core/src/main/scala/org/apache/gearpump/util/Graph.scala
+++ b/core/src/main/scala/org/apache/gearpump/util/Graph.scala
@@ -318,8 +318,12 @@
    * http://www.drdobbs.com/database/topological-sorting/184410262
    */
   def topologicalOrderWithCirclesIterator: Iterator[N] = {
-    val topo = getAcyclicCopy().topologicalOrderIterator
-    topo.flatMap(_.sortBy(_indexs(_)).iterator)
+    if (hasCycle()) {
+      val topo = getAcyclicCopy().topologicalOrderIterator
+      topo.flatMap(_.sortBy(_indexs(_)).iterator)
+    } else {
+      topologicalOrderIterator
+    }
   }
 
   private def getAcyclicCopy(): Graph[mutable.MutableList[N], E] = {