Skip to content

Commit f5a8d1f

Browse files
author
alanw
committed
completed 3.0.2 integration - all unit tests pass
Closes #2
1 parent acf8a9d commit f5a8d1f

11 files changed

+261
-14
lines changed

include/CachingSpanFilter.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ namespace Lucene
2525
protected:
2626
SpanFilterPtr filter;
2727
FilterCachePtr cache;
28-
28+
29+
public:
2930
// for testing
3031
int32_t hitCount;
3132
int32_t missCount;

include/FilteredDocIdSet.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ namespace Lucene
6060
LUCENE_CLASS(DefaultFilteredDocIdSetIterator);
6161

6262
protected:
63-
FilteredDocIdSetWeakPtr _filtered;
63+
FilteredDocIdSetPtr filtered;
6464

6565
protected:
6666
virtual bool match(int32_t docid);

include/SegmentReader.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ namespace Lucene
230230
/// closed, even those it shares core objects with other SegmentReaders
231231
SegmentReaderRefPtr ref;
232232

233-
SegmentReaderPtr origInstance;
233+
SegmentReaderWeakPtr _origInstance;
234234

235235
public:
236236
String segment;

index/SegmentReader.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -836,7 +836,7 @@ namespace Lucene
836836

837837
// Must assign this at the end -- if we hit an exception above core, we don't want to attempt to
838838
// purge the FieldCache (will hit NPE because core is not assigned yet).
839-
this->origInstance = origInstance;
839+
_origInstance = origInstance;
840840
}
841841

842842
CoreReaders::~CoreReaders()
@@ -928,6 +928,7 @@ namespace Lucene
928928
storeCFSReader->close();
929929

930930
// Force FieldCache to evict our entries at this point
931+
SegmentReaderPtr origInstance(_origInstance.lock());
931932
if (origInstance)
932933
FieldCache::DEFAULT()->purge(origInstance);
933934
}

search/FilteredDocIdSet.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ namespace Lucene
3030

3131
DefaultFilteredDocIdSetIterator::DefaultFilteredDocIdSetIterator(FilteredDocIdSetPtr filtered, DocIdSetIteratorPtr innerIter) : FilteredDocIdSetIterator(innerIter)
3232
{
33-
_filtered = filtered;
33+
this->filtered = filtered;
3434
}
3535

3636
DefaultFilteredDocIdSetIterator::~DefaultFilteredDocIdSetIterator()
@@ -39,6 +39,6 @@ namespace Lucene
3939

4040
bool DefaultFilteredDocIdSetIterator::match(int32_t docid)
4141
{
42-
return FilteredDocIdSetPtr(_filtered)->match(docid);
42+
return filtered->match(docid);
4343
}
4444
}

store/NativeFSLockFactory.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,13 @@ namespace Lucene
8080

8181
NativeFSLock::~NativeFSLock()
8282
{
83-
release();
83+
try
84+
{
85+
release();
86+
}
87+
catch (...)
88+
{
89+
}
8490
}
8591

8692
SynchronizePtr NativeFSLock::LOCK_HELD_LOCK()

test/index/IndexCommitTest.cpp

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
/////////////////////////////////////////////////////////////////////////////
2+
// Copyright (c) 2009-2010 Alan Wright. All rights reserved.
3+
// Distributable under the terms of either the Apache License (Version 2.0)
4+
// or the GNU Lesser General Public License.
5+
/////////////////////////////////////////////////////////////////////////////
6+
7+
#include "stdafx.h"
8+
#include "LuceneTestFixture.h"
9+
#include "RAMDirectory.h"
10+
#include "IndexCommit.h"
11+
12+
using namespace Lucene;
13+
14+
BOOST_FIXTURE_TEST_SUITE(IndexCommitTest, LuceneTestFixture)
15+
16+
namespace TestEqualsHashCode
17+
{
18+
class TestIndexCommit1 : public IndexCommit
19+
{
20+
public:
21+
TestIndexCommit1(DirectoryPtr dir)
22+
{
23+
this->dir = dir;
24+
}
25+
26+
virtual ~TestIndexCommit1()
27+
{
28+
}
29+
30+
protected:
31+
DirectoryPtr dir;
32+
33+
public:
34+
virtual String getSegmentsFileName()
35+
{
36+
return L"a";
37+
}
38+
39+
virtual int64_t getVersion()
40+
{
41+
return 12;
42+
}
43+
44+
virtual DirectoryPtr getDirectory()
45+
{
46+
return dir;
47+
}
48+
49+
virtual HashSet<String> getFileNames()
50+
{
51+
return HashSet<String>();
52+
}
53+
54+
virtual void deleteCommit()
55+
{
56+
}
57+
58+
virtual int64_t getGeneration()
59+
{
60+
return 0;
61+
}
62+
63+
virtual int64_t getTimestamp()
64+
{
65+
return -1;
66+
}
67+
68+
virtual MapStringString getUserData()
69+
{
70+
return MapStringString();
71+
}
72+
73+
virtual bool isDeleted()
74+
{
75+
return false;
76+
}
77+
78+
virtual bool isOptimized()
79+
{
80+
return false;
81+
}
82+
};
83+
84+
class TestIndexCommit2 : public TestIndexCommit1
85+
{
86+
public:
87+
TestIndexCommit2(DirectoryPtr dir) : TestIndexCommit1(dir)
88+
{
89+
}
90+
91+
virtual ~TestIndexCommit2()
92+
{
93+
}
94+
95+
public:
96+
virtual String getSegmentsFileName()
97+
{
98+
return L"b";
99+
}
100+
};
101+
}
102+
103+
BOOST_AUTO_TEST_CASE(testEqualsHashCode)
104+
{
105+
DirectoryPtr dir = newLucene<RAMDirectory>();
106+
107+
IndexCommitPtr ic1 = newLucene<TestEqualsHashCode::TestIndexCommit1>(dir);
108+
IndexCommitPtr ic2 = newLucene<TestEqualsHashCode::TestIndexCommit2>(dir);
109+
110+
BOOST_CHECK(ic1->equals(ic2));
111+
BOOST_CHECK_EQUAL(ic1->hashCode(), ic2->hashCode());
112+
}
113+
114+
BOOST_AUTO_TEST_SUITE_END()

test/msvc/lucene_tester.vcproj

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -427,6 +427,10 @@
427427
RelativePath="..\index\FilterIndexReaderTest.cpp"
428428
>
429429
</File>
430+
<File
431+
RelativePath="..\index\IndexCommitTest.cpp"
432+
>
433+
</File>
430434
<File
431435
RelativePath="..\index\IndexFileDeleterTest.cpp"
432436
>
@@ -801,6 +805,10 @@
801805
RelativePath="..\search\BooleanScorerTest.cpp"
802806
>
803807
</File>
808+
<File
809+
RelativePath="..\search\CachingSpanFilterTest.cpp"
810+
>
811+
</File>
804812
<File
805813
RelativePath="..\search\CachingWrapperFilterTest.cpp"
806814
>

test/search/CachingSpanFilterTest.cpp

Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
/////////////////////////////////////////////////////////////////////////////
2+
// Copyright (c) 2009-2010 Alan Wright. All rights reserved.
3+
// Distributable under the terms of either the Apache License (Version 2.0)
4+
// or the GNU Lesser General Public License.
5+
/////////////////////////////////////////////////////////////////////////////
6+
7+
#include "stdafx.h"
8+
#include "LuceneTestFixture.h"
9+
#include "MockRAMDirectory.h"
10+
#include "CachingSpanFilter.h"
11+
#include "CachingWrapperFilter.h"
12+
#include "IndexWriter.h"
13+
#include "WhitespaceAnalyzer.h"
14+
#include "IndexReader.h"
15+
#include "IndexSearcher.h"
16+
#include "Field.h"
17+
#include "Document.h"
18+
#include "TopDocs.h"
19+
#include "ScoreDoc.h"
20+
#include "MatchAllDocsQuery.h"
21+
#include "ConstantScoreQuery.h"
22+
#include "SpanFilter.h"
23+
#include "SpanTermQuery.h"
24+
#include "SpanQueryFilter.h"
25+
#include "TermQuery.h"
26+
#include "Term.h"
27+
28+
using namespace Lucene;
29+
30+
BOOST_FIXTURE_TEST_SUITE(CachingSpanFilterTest, LuceneTestFixture)
31+
32+
static IndexReaderPtr refreshReader(IndexReaderPtr reader)
33+
{
34+
IndexReaderPtr oldReader = reader;
35+
reader = reader->reopen();
36+
if (reader != oldReader)
37+
oldReader->close();
38+
return reader;
39+
}
40+
41+
BOOST_AUTO_TEST_CASE(testEnforceDeletions)
42+
{
43+
DirectoryPtr dir = newLucene<MockRAMDirectory>();
44+
IndexWriterPtr writer = newLucene<IndexWriter>(dir, newLucene<WhitespaceAnalyzer>(), IndexWriter::MaxFieldLengthUNLIMITED);
45+
IndexReaderPtr reader = writer->getReader();
46+
IndexSearcherPtr searcher = newLucene<IndexSearcher>(reader);
47+
48+
// add a doc, refresh the reader, and check that its there
49+
DocumentPtr doc = newLucene<Document>();
50+
doc->add(newLucene<Field>(L"id", L"1", Field::STORE_YES, Field::INDEX_NOT_ANALYZED));
51+
writer->addDocument(doc);
52+
53+
reader = refreshReader(reader);
54+
searcher = newLucene<IndexSearcher>(reader);
55+
56+
TopDocsPtr docs = searcher->search(newLucene<MatchAllDocsQuery>(), 1);
57+
BOOST_CHECK_EQUAL(1, docs->totalHits);
58+
59+
SpanFilterPtr startFilter = newLucene<SpanQueryFilter>(newLucene<SpanTermQuery>(newLucene<Term>(L"id", L"1")));
60+
61+
// ignore deletions
62+
CachingSpanFilterPtr filter = newLucene<CachingSpanFilter>(startFilter, CachingWrapperFilter::DELETES_IGNORE);
63+
64+
docs = searcher->search(newLucene<MatchAllDocsQuery>(), filter, 1);
65+
BOOST_CHECK_EQUAL(1, docs->totalHits);
66+
ConstantScoreQueryPtr constantScore = newLucene<ConstantScoreQuery>(filter);
67+
docs = searcher->search(constantScore, 1);
68+
BOOST_CHECK_EQUAL(1, docs->totalHits);
69+
70+
// now delete the doc, refresh the reader, and see that it's not there
71+
writer->deleteDocuments(newLucene<Term>(L"id", L"1"));
72+
73+
reader = refreshReader(reader);
74+
searcher = newLucene<IndexSearcher>(reader);
75+
76+
docs = searcher->search(newLucene<MatchAllDocsQuery>(), filter, 1);
77+
BOOST_CHECK_EQUAL(0, docs->totalHits);
78+
79+
docs = searcher->search(constantScore, 1);
80+
BOOST_CHECK_EQUAL(1, docs->totalHits);
81+
82+
// force cache to regenerate
83+
filter = newLucene<CachingSpanFilter>(startFilter, CachingWrapperFilter::DELETES_RECACHE);
84+
85+
writer->addDocument(doc);
86+
reader = refreshReader(reader);
87+
searcher = newLucene<IndexSearcher>(reader);
88+
89+
docs = searcher->search(newLucene<MatchAllDocsQuery>(), filter, 1);
90+
BOOST_CHECK_EQUAL(1, docs->totalHits);
91+
92+
constantScore = newLucene<ConstantScoreQuery>(filter);
93+
docs = searcher->search(constantScore, 1);
94+
BOOST_CHECK_EQUAL(1, docs->totalHits);
95+
96+
// make sure we get a cache hit when we reopen readers that had no new deletions
97+
IndexReaderPtr newReader = refreshReader(reader);
98+
BOOST_CHECK_NE(reader, newReader);
99+
reader = newReader;
100+
searcher = newLucene<IndexSearcher>(reader);
101+
int32_t missCount = filter->missCount;
102+
docs = searcher->search(constantScore, 1);
103+
BOOST_CHECK_EQUAL(1, docs->totalHits);
104+
BOOST_CHECK_EQUAL(missCount, filter->missCount);
105+
106+
// now delete the doc, refresh the reader, and see that it's not there
107+
writer->deleteDocuments(newLucene<Term>(L"id", L"1"));
108+
109+
reader = refreshReader(reader);
110+
searcher = newLucene<IndexSearcher>(reader);
111+
112+
docs = searcher->search(newLucene<MatchAllDocsQuery>(), filter, 1);
113+
BOOST_CHECK_EQUAL(0, docs->totalHits);
114+
115+
docs = searcher->search(constantScore, 1);
116+
BOOST_CHECK_EQUAL(0, docs->totalHits);
117+
}
118+
119+
BOOST_AUTO_TEST_SUITE_END()

test/search/CachingWrapperFilterTest.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ BOOST_AUTO_TEST_CASE(testEnforceDeletions)
240240
docs = searcher->search(constantScore, 1);
241241
BOOST_CHECK_EQUAL(1, docs->totalHits);
242242

243-
// force cache to regenerate:
243+
// force cache to regenerate
244244
filter = newLucene<CachingWrapperFilter>(startFilter, CachingWrapperFilter::DELETES_RECACHE);
245245

246246
writer->addDocument(doc);

0 commit comments

Comments
 (0)