2013-08-23 22:13:42 +00:00
|
|
|
/*
|
2018-01-04 00:52:49 +00:00
|
|
|
Copyright 2011 The Perkeep Authors
|
2013-08-23 22:13:42 +00:00
|
|
|
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
You may obtain a copy of the License at
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
limitations under the License.
|
|
|
|
*/
|
|
|
|
|
2014-04-01 16:03:20 +00:00
|
|
|
package index_test
|
2013-08-23 22:13:42 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"path/filepath"
|
|
|
|
"testing"
|
|
|
|
|
Rename import paths from camlistore.org to perkeep.org.
Part of the project renaming, issue #981.
After this, users will need to mv their $GOPATH/src/camlistore.org to
$GOPATH/src/perkeep.org. Sorry.
This doesn't yet rename the tools like camlistored, camput, camget,
camtool, etc.
Also, this only moves the lru package to internal. More will move to
internal later.
Also, this doesn't yet remove the "/pkg/" directory. That'll likely
happen later.
This updates some docs, but not all.
devcam test now passes again, even with Go 1.10 (which requires vet
checks are clean too). So a bunch of vet tests are fixed in this CL
too, and a bunch of other broken tests are now fixed (introduced from
the past week of merging the CL backlog).
Change-Id: If580db1691b5b99f8ed6195070789b1f44877dd4
2018-01-01 22:41:41 +00:00
|
|
|
"perkeep.org/pkg/index"
|
|
|
|
"perkeep.org/pkg/index/indextest"
|
|
|
|
"perkeep.org/pkg/sorted"
|
|
|
|
"perkeep.org/pkg/sorted/kvfile"
|
|
|
|
"perkeep.org/pkg/sorted/kvtest"
|
|
|
|
"perkeep.org/pkg/test"
|
2013-08-23 22:13:42 +00:00
|
|
|
)
|
|
|
|
|
2024-01-14 19:18:12 +00:00
|
|
|
func newKvfileSorted(t *testing.T) sorted.KeyValue {
|
2022-01-23 11:24:37 +00:00
|
|
|
td := t.TempDir()
|
|
|
|
kv, err := kvfile.NewStorage(filepath.Join(td, "kvfile"))
|
2013-12-07 16:43:18 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2024-01-14 19:18:12 +00:00
|
|
|
t.Cleanup(func() { kv.Close() })
|
|
|
|
return kv
|
2013-12-07 16:43:18 +00:00
|
|
|
}
|
|
|
|
|
2014-04-01 16:03:20 +00:00
|
|
|
func TestSorted_Kvfile(t *testing.T) {
|
2024-01-14 19:18:12 +00:00
|
|
|
kv := newKvfileSorted(t)
|
2013-12-07 16:43:18 +00:00
|
|
|
kvtest.TestSorted(t, kv)
|
|
|
|
}
|
|
|
|
|
2014-04-01 16:03:20 +00:00
|
|
|
func indexTest(t *testing.T,
|
2024-01-14 19:18:12 +00:00
|
|
|
sortedGenfn func(t *testing.T) sorted.KeyValue,
|
2014-04-01 16:03:20 +00:00
|
|
|
tfn func(*testing.T, func() *index.Index)) {
|
2013-12-07 16:43:18 +00:00
|
|
|
defer test.TLog(t)()
|
2024-01-14 19:18:12 +00:00
|
|
|
|
2014-04-01 16:03:20 +00:00
|
|
|
makeIndex := func() *index.Index {
|
2024-01-14 19:18:12 +00:00
|
|
|
s := sortedGenfn(t)
|
2016-02-05 14:56:16 +00:00
|
|
|
return indextest.MustNew(t, s)
|
2013-08-23 22:13:42 +00:00
|
|
|
}
|
2014-04-01 16:03:20 +00:00
|
|
|
tfn(t, makeIndex)
|
2013-08-23 22:13:42 +00:00
|
|
|
}
|
|
|
|
|
2014-04-01 16:03:20 +00:00
|
|
|
func TestIndex_Kvfile(t *testing.T) {
|
|
|
|
indexTest(t, newKvfileSorted, indextest.Index)
|
2013-08-23 22:13:42 +00:00
|
|
|
}
|
|
|
|
|
2014-04-01 16:03:20 +00:00
|
|
|
func TestPathsOfSignerTarget_Kvfile(t *testing.T) {
|
|
|
|
indexTest(t, newKvfileSorted, indextest.PathsOfSignerTarget)
|
2013-08-23 22:13:42 +00:00
|
|
|
}
|
|
|
|
|
2014-04-01 16:03:20 +00:00
|
|
|
func TestFiles_Kvfile(t *testing.T) {
|
|
|
|
indexTest(t, newKvfileSorted, indextest.Files)
|
2013-08-23 22:13:42 +00:00
|
|
|
}
|
|
|
|
|
2014-04-01 16:03:20 +00:00
|
|
|
func TestEdgesTo_Kvfile(t *testing.T) {
|
|
|
|
indexTest(t, newKvfileSorted, indextest.EdgesTo)
|
2013-08-23 22:13:42 +00:00
|
|
|
}
|
2013-11-04 22:15:24 +00:00
|
|
|
|
2014-04-01 16:03:20 +00:00
|
|
|
func TestDelete_Kvfile(t *testing.T) {
|
|
|
|
indexTest(t, newKvfileSorted, indextest.Delete)
|
2013-11-04 22:15:24 +00:00
|
|
|
}
|
index: actually reindex when out of order
problem: the out-of-order mechanism based on the outOfOrderIndexerLoop
was not working for some claims.
Let C be a delete claim on permanode P. If C was received before P was,
C was marked as being received with the "have" index row. However, for
the deletion to be marked in the index, some information about P is
needed (its meta row), so C could not be fully indexed upon reception.
Then, when P was finally received, the outOfOrderIndexerLoop would kick
in and retry indexing C. Which would fail, because a test based on the
"have" row would (wrongly) detect that C is already indexed and return
early.
In this patch:
-we introduce the "|indexed" suffix to the "have" - value part - row
(receive.go). If a blob is received but some of its dependencies are
missing, the have row value is written without the suffix. Upon
reception of a blob, we now test for the presence of the suffix in the
have row. If missing, the reception continues instead of returning
early. The existing mechanism that was detecting missing dependencies
for file blobs has been adapted to work with this suffix too.
-the index enumeration (enumstat.go), which relies on "have" rows, has
been adapted to work with the new "have" row format, while staying
compatible with the old format. And related tests have been added.
http://camlistore.org/issue/454
Change-Id: I2559d08a12b2a4e0f0691fc7e31f1ed1f874625e
2014-07-03 16:07:08 +00:00
|
|
|
|
|
|
|
func TestReindex_Kvfile(t *testing.T) {
|
|
|
|
indexTest(t, newKvfileSorted, indextest.Reindex)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestEnumStat_Kvfile(t *testing.T) {
|
|
|
|
indexTest(t, newKvfileSorted, indextest.EnumStat)
|
|
|
|
}
|