rules_test.go 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713
  1. /*
  2. * EliasDB
  3. *
  4. * Copyright 2016 Matthias Ladkau. All rights reserved.
  5. *
  6. * This Source Code Form is subject to the terms of the Mozilla Public
  7. * License, v. 2.0. If a copy of the MPL was not distributed with this
  8. * file, You can obtain one at http://mozilla.org/MPL/2.0/.
  9. */
  10. package graph
  11. import (
  12. "fmt"
  13. "testing"
  14. "devt.de/krotik/eliasdb/graph/data"
  15. "devt.de/krotik/eliasdb/graph/graphstorage"
  16. "devt.de/krotik/eliasdb/graph/util"
  17. )
  18. type TestRule struct {
  19. handleError bool
  20. commitError bool
  21. }
  22. func (r *TestRule) Name() string {
  23. return "testrule"
  24. }
  25. func (r *TestRule) Handles() []int {
  26. return []int{EventNodeCreated, EventNodeUpdated, EventNodeDeleted,
  27. EventEdgeCreated, EventEdgeUpdated, EventEdgeDeleted}
  28. }
  29. func (r *TestRule) Handle(gm *Manager, trans Trans, event int, ed ...interface{}) error {
  30. if r.handleError {
  31. return &util.GraphError{Type: util.ErrAccessComponent, Detail: "Test error"}
  32. }
  33. if r.commitError {
  34. node := data.NewGraphNode()
  35. node.SetAttr("key", "123")
  36. node.SetAttr("kind", "bla")
  37. edge := data.NewGraphEdge()
  38. edge.SetAttr("key", "123")
  39. edge.SetAttr("kind", "myedge")
  40. edge.SetAttr(data.EdgeEnd1Key, node.Key())
  41. edge.SetAttr(data.EdgeEnd1Kind, node.Kind())
  42. edge.SetAttr(data.EdgeEnd1Role, "node1")
  43. edge.SetAttr(data.EdgeEnd1Cascading, false)
  44. edge.SetAttr(data.EdgeEnd2Key, node.Key())
  45. edge.SetAttr(data.EdgeEnd2Kind, node.Kind())
  46. edge.SetAttr(data.EdgeEnd2Role, "node2")
  47. edge.SetAttr(data.EdgeEnd2Cascading, false)
  48. trans.StoreEdge("test", edge)
  49. }
  50. return nil
  51. }
  52. func TestCascadingLastRules(t *testing.T) {
  53. mgs := graphstorage.NewMemoryGraphStorage("mystorage")
  54. gm := NewGraphManager(mgs)
  55. constructEdge := func(key string, node1 data.Node, node2 data.Node) data.Edge {
  56. edge := data.NewGraphEdge()
  57. edge.SetAttr("key", key)
  58. edge.SetAttr("kind", "myedge")
  59. edge.SetAttr(data.EdgeEnd1Key, node1.Key())
  60. edge.SetAttr(data.EdgeEnd1Kind, node1.Kind())
  61. edge.SetAttr(data.EdgeEnd1Role, "node1")
  62. edge.SetAttr(data.EdgeEnd1Cascading, true)
  63. edge.SetAttr(data.EdgeEnd1CascadingLast, true)
  64. edge.SetAttr(data.EdgeEnd2Key, node2.Key())
  65. edge.SetAttr(data.EdgeEnd2Kind, node2.Kind())
  66. edge.SetAttr(data.EdgeEnd2Role, "node2")
  67. edge.SetAttr(data.EdgeEnd2Cascading, false)
  68. edge.SetAttr(data.NodeName, "Edge1"+key)
  69. return edge
  70. }
  71. node1 := data.NewGraphNode()
  72. node1.SetAttr("key", "123")
  73. node1.SetAttr("kind", "Artist")
  74. node1.SetAttr("Name", "Artist1")
  75. gm.StoreNode("main", node1)
  76. node2 := data.NewGraphNode()
  77. node2.SetAttr("key", "456")
  78. node2.SetAttr("kind", "Song")
  79. node2.SetAttr("Name", "Song1")
  80. gm.StoreNode("main", node2)
  81. node3 := data.NewGraphNode()
  82. node3.SetAttr("key", "789")
  83. node3.SetAttr("kind", "Song")
  84. node3.SetAttr("Name", "Song2")
  85. gm.StoreNode("main", node3)
  86. gm.StoreEdge("main", constructEdge("abc1", node2, node1))
  87. gm.StoreEdge("main", constructEdge("abc2", node3, node1))
  88. gm.RemoveNode("main", "456", "Song")
  89. n, _ := gm.FetchNode("main", "123", "Artist")
  90. if n == nil {
  91. t.Error("Artist node should have not been deleted")
  92. return
  93. }
  94. gm.RemoveNode("main", "789", "Song")
  95. n, _ = gm.FetchNode("main", "123", "Artist")
  96. if n != nil {
  97. t.Error("Last removed Song node should have deleted the Artist node")
  98. return
  99. }
  100. // Now again but with multiple relationships
  101. mgs = graphstorage.NewMemoryGraphStorage("mystorage")
  102. gm = NewGraphManager(mgs)
  103. node1 = data.NewGraphNode()
  104. node1.SetAttr("key", "123")
  105. node1.SetAttr("kind", "Artist")
  106. node1.SetAttr("Name", "Artist1")
  107. gm.StoreNode("main", node1)
  108. node2 = data.NewGraphNode()
  109. node2.SetAttr("key", "456")
  110. node2.SetAttr("kind", "Song")
  111. node2.SetAttr("Name", "Song1")
  112. gm.StoreNode("main", node2)
  113. gm.StoreEdge("main", constructEdge("abc1", node2, node1))
  114. gm.StoreEdge("main", constructEdge("abc2", node2, node1))
  115. gm.RemoveNode("main", "456", "Song")
  116. n, _ = gm.FetchNode("main", "123", "Artist")
  117. if n != nil {
  118. t.Error("Artist node should have been deleted")
  119. return
  120. }
  121. }
  122. func TestRules(t *testing.T) {
  123. mgs := graphstorage.NewMemoryGraphStorage("mystorage")
  124. gm := NewGraphManager(mgs)
  125. constructEdge := func(key string, node1 data.Node, node2 data.Node) data.Edge {
  126. edge := data.NewGraphEdge()
  127. edge.SetAttr("key", key)
  128. edge.SetAttr("kind", "myedge")
  129. edge.SetAttr(data.EdgeEnd1Key, node1.Key())
  130. edge.SetAttr(data.EdgeEnd1Kind, node1.Kind())
  131. edge.SetAttr(data.EdgeEnd1Role, "node1")
  132. edge.SetAttr(data.EdgeEnd1Cascading, true)
  133. edge.SetAttr(data.EdgeEnd2Key, node2.Key())
  134. edge.SetAttr(data.EdgeEnd2Kind, node2.Kind())
  135. edge.SetAttr(data.EdgeEnd2Role, "node2")
  136. edge.SetAttr(data.EdgeEnd2Cascading, false)
  137. edge.SetAttr(data.NodeName, "Edge1"+key)
  138. return edge
  139. }
  140. constructGraph := func() {
  141. mgs = graphstorage.NewMemoryGraphStorage("mystorage")
  142. gm = NewGraphManager(mgs)
  143. node1 := data.NewGraphNode()
  144. node1.SetAttr("key", "123")
  145. node1.SetAttr("kind", "mynode")
  146. node1.SetAttr("Name", "Node1")
  147. gm.StoreNode("main", node1)
  148. node2 := data.NewGraphNode()
  149. node2.SetAttr("key", "456")
  150. node2.SetAttr("kind", "mynewnode")
  151. node2.SetAttr("Name", "Node2")
  152. gm.StoreNode("main", node2)
  153. node3 := data.NewGraphNode()
  154. node3.SetAttr("key", "789")
  155. node3.SetAttr("kind", "mynewnode")
  156. node3.SetAttr("Name", "Node3")
  157. gm.StoreNode("main", node3)
  158. node4 := data.NewGraphNode()
  159. node4.SetAttr("key", "xxx")
  160. node4.SetAttr("kind", "mynewnode")
  161. node4.SetAttr("Name", "Node4")
  162. gm.StoreNode("main", node4)
  163. gm.StoreEdge("main", constructEdge("abc2", node1, node2))
  164. gm.StoreEdge("main", constructEdge("abc3", node1, node2))
  165. gm.StoreEdge("main", constructEdge("abc1", node2, node3))
  166. gm.StoreEdge("main", constructEdge("abc0", node3, node4))
  167. gm.StoreEdge("main", constructEdge("abc99", node4, node1))
  168. }
  169. // Check rules on empty graph
  170. if len(gm.NodeKinds()) != 0 {
  171. t.Error("Unexpected node kinds result")
  172. return
  173. }
  174. if len(gm.Partitions()) != 0 {
  175. t.Error("Unexpected node kinds result")
  176. return
  177. }
  178. if len(gm.EdgeKinds()) != 0 {
  179. t.Error("Unexpected node kinds result")
  180. return
  181. }
  182. if len(gm.NodeAttrs("test")) != 0 {
  183. t.Error("Unexpected node attributes result")
  184. return
  185. }
  186. if _, err := gm.RemoveNode("test", "test", "test"); err != nil {
  187. t.Error(err)
  188. return
  189. }
  190. constructGraph()
  191. if res := fmt.Sprint(gm.NodeKinds()); res != "[mynewnode mynode]" {
  192. t.Error("Unexpected node kinds result:", res)
  193. return
  194. }
  195. if res := fmt.Sprint(gm.EdgeKinds()); res != "[myedge]" {
  196. t.Error("Unexpected edge kinds result:", res)
  197. return
  198. }
  199. if res := fmt.Sprint(gm.Partitions()); res != "[main]" {
  200. t.Error("Unexpected partitions result:", res)
  201. return
  202. }
  203. if res := fmt.Sprint(gm.NodeAttrs("mynode")); res != "[Name key kind]" {
  204. t.Error("Unexpected node attributes result:", res)
  205. return
  206. }
  207. // Test updating a node
  208. node1 := data.NewGraphNode()
  209. node1.SetAttr("key", "123")
  210. node1.SetAttr("kind", "mynode")
  211. node1.SetAttr("Name2", "Node1Name2")
  212. gm.StoreNode("main", node1)
  213. if res := fmt.Sprint(gm.NodeAttrs("mynode")); res != "[Name Name2 key kind]" {
  214. t.Error("Unexpected node attributes result:", res)
  215. return
  216. }
  217. // Test edge specs
  218. if res := fmt.Sprint(gm.NodeEdges("mynode")); res != "[node1:myedge:node2:mynewnode node2:myedge:node1:mynewnode]" {
  219. t.Error("Unexpected node attributes result:", res)
  220. return
  221. }
  222. if res := fmt.Sprint(gm.EdgeAttrs("myedge")); res != "[end1cascading end1key end1kind end1role end2cascading end2key end2kind end2role key kind name]" {
  223. t.Error("Unexpected node attributes result:", res)
  224. return
  225. }
  226. if c := gm.NodeCount("mynode"); c != 1 {
  227. t.Error("Unexpected node count:", c)
  228. return
  229. } else if c := gm.NodeCount("mynewnode"); c != 3 {
  230. t.Error("Unexpected node count:", c)
  231. return
  232. } else if c := gm.EdgeCount("myedge"); c != 5 {
  233. t.Error("Unexpected edge count:", c)
  234. return
  235. }
  236. gm.RemoveNode("main", "123", "mynode")
  237. if c := gm.NodeCount("mynode"); c != 0 {
  238. t.Error("Unexpected node count:", c)
  239. return
  240. } else if c := gm.NodeCount("mynewnode"); c != 0 {
  241. t.Error("Unexpected node count:", c)
  242. return
  243. } else if c := gm.EdgeCount("myedge"); c != 0 {
  244. t.Error("Unexpected edge count:", c)
  245. return
  246. }
  247. // Finally test a rather esotheric error case
  248. trans := NewConcurrentGraphTrans(gm)
  249. err := gm.gr.graphEvent(trans, EventNodeDeleted, "test 1", node1)
  250. if err.Error() !=
  251. "GraphError: Graph rule error (GraphError: Invalid data (Partition name "+
  252. "test 1 is not alphanumeric - can only contain [a-zA-Z0-9_]))" {
  253. t.Error(err)
  254. return
  255. }
  256. }
  257. func TestRulesTrans(t *testing.T) {
  258. mgs := graphstorage.NewMemoryGraphStorage("mystorage")
  259. gm := NewGraphManager(mgs)
  260. constructEdge := func(key string, node1 data.Node, node2 data.Node) data.Edge {
  261. edge := data.NewGraphEdge()
  262. edge.SetAttr("key", key)
  263. edge.SetAttr("kind", "myedge")
  264. edge.SetAttr(data.EdgeEnd1Key, node1.Key())
  265. edge.SetAttr(data.EdgeEnd1Kind, node1.Kind())
  266. edge.SetAttr(data.EdgeEnd1Role, "node1")
  267. edge.SetAttr(data.EdgeEnd1Cascading, true)
  268. edge.SetAttr(data.EdgeEnd2Key, node2.Key())
  269. edge.SetAttr(data.EdgeEnd2Kind, node2.Kind())
  270. edge.SetAttr(data.EdgeEnd2Role, "node2")
  271. edge.SetAttr(data.EdgeEnd2Cascading, false)
  272. edge.SetAttr(data.NodeName, "Edge1"+key)
  273. return edge
  274. }
  275. constructGraph := func() {
  276. mgs = graphstorage.NewMemoryGraphStorage("mystorage")
  277. gm = NewGraphManager(mgs)
  278. node1 := data.NewGraphNode()
  279. node1.SetAttr("key", "123")
  280. node1.SetAttr("kind", "mynode")
  281. node1.SetAttr("Name", "Node1")
  282. gm.StoreNode("main", node1)
  283. node2 := data.NewGraphNode()
  284. node2.SetAttr("key", "456")
  285. node2.SetAttr("kind", "mynewnode")
  286. node2.SetAttr("Name", "Node2")
  287. gm.StoreNode("main", node2)
  288. node3 := data.NewGraphNode()
  289. node3.SetAttr("key", "789")
  290. node3.SetAttr("kind", "mynewnode")
  291. node3.SetAttr("Name", "Node3")
  292. gm.StoreNode("main", node3)
  293. node4 := data.NewGraphNode()
  294. node4.SetAttr("key", "xxx")
  295. node4.SetAttr("kind", "mynewnode")
  296. node4.SetAttr("Name", "Node4")
  297. gm.StoreNode("main", node4)
  298. gm.StoreEdge("main", constructEdge("abc2", node1, node2))
  299. gm.StoreEdge("main", constructEdge("abc3", node1, node2))
  300. gm.StoreEdge("main", constructEdge("abc1", node2, node3))
  301. gm.StoreEdge("main", constructEdge("abc0", node3, node4))
  302. gm.StoreEdge("main", constructEdge("abc99", node4, node1))
  303. }
  304. // Check rules on empty graph
  305. if _, err := gm.RemoveNode("test", "test", "test"); err != nil {
  306. t.Error(err)
  307. return
  308. }
  309. constructGraph()
  310. if c := gm.NodeCount("mynode"); c != 1 {
  311. t.Error("Unexpected node count:", c)
  312. return
  313. } else if c := gm.NodeCount("mynewnode"); c != 3 {
  314. t.Error("Unexpected node count:", c)
  315. return
  316. } else if c := gm.EdgeCount("myedge"); c != 5 {
  317. t.Error("Unexpected edge count:", c)
  318. return
  319. }
  320. trans := NewConcurrentGraphTrans(gm)
  321. trans.RemoveNode("main", "123", "mynode")
  322. if err := trans.Commit(); err != nil {
  323. t.Error(err)
  324. return
  325. }
  326. if c := gm.NodeCount("mynode"); c != 0 {
  327. t.Error("Unexpected node count:", c)
  328. return
  329. } else if c := gm.NodeCount("mynewnode"); c != 0 {
  330. t.Error("Unexpected node count:", c)
  331. return
  332. } else if c := gm.EdgeCount("myedge"); c != 0 {
  333. t.Error("Unexpected edge count:", c)
  334. return
  335. }
  336. }
  337. func TestRulesErrors(t *testing.T) {
  338. mgs := graphstorage.NewMemoryGraphStorage("mystorage")
  339. gm := NewGraphManager(mgs)
  340. tr := &TestRule{false, false}
  341. gm.SetGraphRule(tr)
  342. // Check that the test rule was added
  343. if rules := fmt.Sprint(gm.GraphRules()); rules !=
  344. "[system.deletenodeedges system.updatenodestats testrule]" {
  345. t.Error("unexpected graph rule list:", rules)
  346. return
  347. }
  348. node1 := data.NewGraphNode()
  349. node1.SetAttr("key", "456")
  350. node1.SetAttr("kind", "mynode")
  351. node1.SetAttr("Name", "Node1")
  352. tr.handleError = true
  353. tr.commitError = false
  354. if err := gm.StoreNode("main", node1); err.Error() !=
  355. "GraphError: Graph rule error (GraphError: Failed to access graph storage component (Test error))" {
  356. t.Error(err)
  357. return
  358. }
  359. tr.handleError = false
  360. tr.commitError = true
  361. if err := gm.StoreNode("main", node1); err.Error() !=
  362. "GraphError: Invalid data (Can't store edge to non-existing node kind: bla)" {
  363. t.Error(err)
  364. return
  365. }
  366. tr.handleError = false
  367. tr.commitError = false
  368. if err := gm.StoreNode("main", node1); err != nil {
  369. t.Error(err)
  370. return
  371. }
  372. tr.handleError = true
  373. tr.commitError = false
  374. if _, err := gm.RemoveNode("main", node1.Key(), node1.Kind()); err.Error() !=
  375. "GraphError: Graph rule error (GraphError: Failed to access graph storage component (Test error))" {
  376. t.Error(err)
  377. return
  378. }
  379. tr.handleError = false
  380. tr.commitError = false
  381. if err := gm.StoreNode("main", node1); err != nil {
  382. t.Error(err)
  383. return
  384. }
  385. tr.handleError = false
  386. tr.commitError = true
  387. if _, err := gm.RemoveNode("main", node1.Key(), node1.Kind()); err.Error() !=
  388. "GraphError: Invalid data (Can't store edge to non-existing node kind: bla)" {
  389. t.Error(err)
  390. return
  391. }
  392. tr.handleError = false
  393. tr.commitError = false
  394. if err := gm.StoreNode("main", node1); err != nil {
  395. t.Error(err)
  396. return
  397. }
  398. tr.handleError = true
  399. tr.commitError = false
  400. edge := data.NewGraphEdge()
  401. edge.SetAttr("key", "123")
  402. edge.SetAttr("kind", "myedge")
  403. edge.SetAttr(data.EdgeEnd1Key, node1.Key())
  404. edge.SetAttr(data.EdgeEnd1Kind, node1.Kind())
  405. edge.SetAttr(data.EdgeEnd1Role, "node1")
  406. edge.SetAttr(data.EdgeEnd1Cascading, false)
  407. edge.SetAttr(data.EdgeEnd2Key, node1.Key())
  408. edge.SetAttr(data.EdgeEnd2Kind, node1.Kind())
  409. edge.SetAttr(data.EdgeEnd2Role, "node2")
  410. edge.SetAttr(data.EdgeEnd2Cascading, false)
  411. if err := gm.StoreEdge("main", edge); err.Error() !=
  412. "GraphError: Graph rule error (GraphError: Failed to access graph storage component (Test error))" {
  413. t.Error(err)
  414. return
  415. }
  416. tr.handleError = false
  417. tr.commitError = true
  418. if err := gm.StoreEdge("main", edge); err.Error() !=
  419. "GraphError: Invalid data (Can't store edge to non-existing node kind: bla)" {
  420. t.Error(err)
  421. return
  422. }
  423. tr.handleError = false
  424. tr.commitError = false
  425. if err := gm.StoreEdge("main", edge); err != nil {
  426. t.Error(err)
  427. return
  428. }
  429. tr.handleError = false
  430. tr.commitError = true
  431. if _, err := gm.RemoveEdge("main", edge.Key(), edge.Kind()); err.Error() !=
  432. "GraphError: Invalid data (Can't store edge to non-existing node kind: bla)" {
  433. t.Error(err)
  434. return
  435. }
  436. tr.handleError = false
  437. tr.commitError = false
  438. if err := gm.StoreEdge("main", edge); err != nil {
  439. t.Error(err)
  440. return
  441. }
  442. tr.handleError = true
  443. tr.commitError = false
  444. if _, err := gm.RemoveEdge("main", edge.Key(), edge.Kind()); err.Error() !=
  445. "GraphError: Graph rule error (GraphError: Failed to access graph storage component (Test error))" {
  446. t.Error(err)
  447. return
  448. }
  449. tr.handleError = false
  450. tr.commitError = false
  451. if err := gm.StoreEdge("main", edge); err != nil {
  452. t.Error(err)
  453. return
  454. }
  455. // Test transaction errors
  456. trans := NewConcurrentGraphTrans(gm)
  457. tr.handleError = true
  458. tr.commitError = false
  459. trans.StoreNode("main", node1)
  460. if err := trans.Commit(); err.Error() !=
  461. "GraphError: Graph rule error (GraphError: Failed to access graph storage component (Test error))" {
  462. t.Error(err)
  463. return
  464. }
  465. tr.handleError = false
  466. tr.commitError = true
  467. trans.StoreNode("main", node1)
  468. if err := trans.Commit(); err.Error() !=
  469. "GraphError: Invalid data (Can't store edge to non-existing node kind: bla)" {
  470. t.Error(err)
  471. return
  472. }
  473. tr.handleError = true
  474. tr.commitError = false
  475. trans.RemoveNode("main", node1.Key(), node1.Kind())
  476. if err := trans.Commit(); err.Error() !=
  477. "GraphError: Graph rule error (GraphError: Failed to access graph storage component (Test error))" {
  478. t.Error(err)
  479. return
  480. }
  481. tr.handleError = false
  482. tr.commitError = false
  483. if err := gm.StoreNode("main", node1); err != nil {
  484. t.Error(err)
  485. return
  486. }
  487. tr.handleError = false
  488. tr.commitError = true
  489. trans.RemoveNode("main", node1.Key(), node1.Kind())
  490. if err := trans.Commit(); err.Error() !=
  491. "GraphError: Invalid data (Can't store edge to non-existing node kind: bla)" {
  492. t.Error(err)
  493. return
  494. }
  495. tr.handleError = false
  496. tr.commitError = false
  497. if err := gm.StoreNode("main", node1); err != nil {
  498. t.Error(err)
  499. return
  500. }
  501. tr.handleError = true
  502. tr.commitError = false
  503. trans.StoreEdge("main", edge)
  504. if err := trans.Commit(); err.Error() !=
  505. "GraphError: Graph rule error (GraphError: Failed to access graph storage component (Test error))" {
  506. t.Error(err)
  507. return
  508. }
  509. tr.handleError = false
  510. tr.commitError = true
  511. trans.StoreEdge("main", edge)
  512. if err := trans.Commit(); err.Error() !=
  513. "GraphError: Invalid data (Can't store edge to non-existing node kind: bla)" {
  514. t.Error(err)
  515. return
  516. }
  517. tr.handleError = false
  518. tr.commitError = false
  519. if err := gm.StoreEdge("main", edge); err != nil {
  520. t.Error(err)
  521. return
  522. }
  523. tr.handleError = false
  524. tr.commitError = true
  525. trans.RemoveEdge("main", edge.Key(), edge.Kind())
  526. if err := trans.Commit(); err.Error() !=
  527. "GraphError: Invalid data (Can't store edge to non-existing node kind: bla)" {
  528. t.Error(err)
  529. return
  530. }
  531. tr.handleError = false
  532. tr.commitError = false
  533. if err := gm.StoreEdge("main", edge); err != nil {
  534. t.Error(err)
  535. return
  536. }
  537. tr.handleError = true
  538. tr.commitError = false
  539. trans.RemoveEdge("main", edge.Key(), edge.Kind())
  540. if err := trans.Commit(); err.Error() !=
  541. "GraphError: Graph rule error (GraphError: Failed to access graph storage component (Test error))" {
  542. t.Error(err)
  543. return
  544. }
  545. }