Skip to content

Commit

Permalink
gae: fix add of previously deleted quads (#580)
Browse files Browse the repository at this point in the history
* fix #578 for adding a previously deleted quad in datastore.

* adding check for deleted quads into checkValid.  This change allows undeleted a quad without the ignore_duplicate option.

* test for issue #578
  • Loading branch information
gkontos authored and dennwc committed May 6, 2017
1 parent 86f3622 commit decd378
Show file tree
Hide file tree
Showing 2 changed files with 125 additions and 1 deletion.
6 changes: 5 additions & 1 deletion graph/gaedatastore/quadstore.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ func (qs *QuadStore) createKeyFromToken(t *Token) *datastore.Key {
}

func (qs *QuadStore) checkValid(k *datastore.Key) (bool, error) {
var q quad.Quad
var q QuadEntry
err := datastore.Get(qs.context, k, &q)
if err == datastore.ErrNoSuchEntity {
return false, nil
Expand All @@ -143,6 +143,10 @@ func (qs *QuadStore) checkValid(k *datastore.Key) (bool, error) {
clog.Warningf("Error occurred when getting quad/node %s %v", k, err)
return false, err
}
// a deleted node should not be returned as found.
if len(q.Deleted) >= len(q.Added) {
return false, nil
}
return true, nil
}

Expand Down
120 changes: 120 additions & 0 deletions graph/graphtest/graphtest.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ func TestAll(t testing.TB, gen DatabaseFunc, conf *Config) {
}
TestLoadTypedQuads(t, gen, conf)
TestAddRemove(t, gen, conf)
TestReAddQuad(t, gen, conf)
TestIteratorsAndNextResultOrderA(t, gen)
if !conf.UnTyped {
TestCompareTypedValues(t, gen, conf)
Expand Down Expand Up @@ -661,6 +662,125 @@ func TestAddRemove(t testing.TB, gen DatabaseFunc, conf *Config) {
ExpectIteratedRawStrings(t, qs, all, expect)
}

// when a quad is deleted, it should be possible to readd the quad without an error
func TestReAddQuad(t testing.TB, gen DatabaseFunc, conf *Config) {
qs, opts, closer := gen(t)
defer closer()

if opts == nil {
opts = make(graph.Options)
}

w := MakeWriter(t, qs, opts, MakeQuadSet()...)

// This quad will be added, removed, and readded
testQuad := quad.MakeRaw("X", "follows", "B", "")

require.Equal(t, int64(11), qs.Size(), "Incorrect number of quads")

all := qs.NodesAllIterator()
expect := []string{
"A",
"B",
"C",
"D",
"E",
"F",
"G",
"cool",
"follows",
"status",
"status_graph",
}
ExpectIteratedRawStrings(t, qs, all, expect)

// Add Test Quad which will be removed and readded
err := w.AddQuadSet([]quad.Quad{
testQuad,
})
assert.Nil(t, err, "AddQuadSet failed")

assert.Equal(t, int64(12), qs.Size(), "Incorrect number of quads")

all = qs.NodesAllIterator()
expect = []string{
"A",
"B",
"C",
"D",
"E",
"F",
"G",
"X",
"cool",
"follows",
"status",
"status_graph",
}
ExpectIteratedRawStrings(t, qs, all, expect)

// Remove quad
err = w.RemoveQuad(testQuad)
require.Nil(t, err, "RemoveQuad failed")

if !conf.SkipNodeDelAfterQuadDel {
expect = []string{
"A",
"B",
"C",
"D",
"E",
"F",
"G",
"cool",
"follows",
"status",
"status_graph",
}
} else {
expect = []string{
"A",
"B",
"C",
"D",
"E",
"F",
"G",
"X",
"cool",
"follows",
"status",
"status_graph",
}
}

// Readd the deleted quad
err = w.AddQuadSet([]quad.Quad{
testQuad,
})
assert.Nil(t, err, "AddQuadSet failed")

assert.Equal(t, int64(12), qs.Size(), "Incorrect number of quads")

all = qs.NodesAllIterator()
expect = []string{
"A",
"B",
"C",
"D",
"E",
"F",
"G",
"X",
"cool",
"follows",
"status",
"status_graph",
}
ExpectIteratedRawStrings(t, qs, all, expect)

}

func TestIteratorsAndNextResultOrderA(t testing.TB, gen DatabaseFunc) {
qs, opts, closer := gen(t)
defer closer()
Expand Down

0 comments on commit decd378

Please sign in to comment.