Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

fix LinkImpl iterator to throw InvalidOperationException when reached…

… end of sequence; Fixed LinkImpl iterator to throw InvalidOperationException when reached end of sequence; thick index code coverage
  • Loading branch information...
commit 9fff4346043c4113af28a32fae8b46005ef5c789 1 parent b462b1c
Krzysztof Kowalczyk authored
2  csharp/changelog-volante.txt
View
@@ -33,3 +33,5 @@
29. Renamed Btree* => OldBtree*, renamed Alt* by removing Alt prefix
30. Fixed bug in IFieldIndex.Contains() where a unique index could claim an object is there when it wasn't
31. Fixed bug in BtreeMultiFieldIndex.Contains() for non-unique index where it would throw an exception
+32. Fixed LinkImpl iterator to throw InvalidOperationException when reached end of sequence
+33. Fixed ThickIndex DictionaryIterator to throw InvalidOperationException when accessing Key when reached end of sequence
15 csharp/src/impl/LinkImpl.cs
View
@@ -252,13 +252,24 @@ class LinkEnumerator : IEnumerator<T>
{
public void Dispose() { }
+ public bool HasMore()
+ {
+ return i + 1 < link.Length;
+ }
+
+ public bool ReachEnd()
+ {
+ return i == link.Length + 1;
+ }
+
public bool MoveNext()
{
- if (i + 1 < link.Length)
+ if (HasMore())
{
i += 1;
return true;
}
+ i = link.Length + 1;
return false;
}
@@ -266,6 +277,8 @@ public T Current
{
get
{
+ if (ReachEnd())
+ throw new InvalidOperationException();
return link[i];
}
}
3  csharp/src/impl/OldBitIndexImpl.cs
View
@@ -194,9 +194,8 @@ public virtual T Current
get
{
if (sp == 0)
- {
throw new InvalidOperationException();
- }
+
int pos = posStack[sp - 1];
Page pg = db.getPage(pageStack[sp - 1]);
IPersistent curr = db.lookupObject(BitIndexPage.getItem(pg, BitIndexPage.maxItems - pos), null);
11 csharp/src/impl/ThickIndex.cs
View
@@ -206,6 +206,8 @@ public object Key
{
get
{
+ if (reachedEnd)
+ throw new InvalidOperationException();
return key;
}
}
@@ -222,10 +224,16 @@ public object Value
public bool MoveNext()
{
+ if (reachedEnd)
+ return false;
+
while (!inner.MoveNext())
{
if (!outer.MoveNext())
+ {
+ reachedEnd = true;
return false;
+ }
key = outer.Key;
inner = ((IEnumerable<V>)outer.Value).GetEnumerator();
@@ -235,8 +243,10 @@ public bool MoveNext()
public void Reset()
{
+ reachedEnd = true;
if (outer.MoveNext())
{
+ reachedEnd = false;
key = outer.Key;
inner = ((IEnumerable<V>)outer.Value).GetEnumerator();
}
@@ -251,6 +261,7 @@ internal ExtendDictionaryEnumerator(IDictionaryEnumerator enumerator)
private IDictionaryEnumerator outer;
private IEnumerator<V> inner;
private object key;
+ private bool reachedEnd;
}
public virtual IDictionaryEnumerator GetDictionaryEnumerator()
67 csharp/tests/Tests/TestIndex.cs
View
@@ -19,7 +19,6 @@ public class Root : Persistent
{
public IIndex<string, RecordFull> strIndex;
public IIndex<long, RecordFull> longIndex;
- public IIndex<byte, RecordFull> thickByteIndex;
}
void MyCommit(IDatabase db, bool serializable)
@@ -35,20 +34,6 @@ void MyCommit(IDatabase db, bool serializable)
}
}
- void RememberInThick(Dictionary<byte, List<RecordFull>> dict, RecordFull rec)
- {
-
- if (dict.ContainsKey(rec.ByteVal))
- {
- var list = dict[rec.ByteVal];
- list.Add(rec);
- }
- else
- {
- dict[rec.ByteVal] = new List<RecordFull>() { rec };
- }
- }
-
public void Run(TestConfig config)
{
int count = config.Count;
@@ -63,14 +48,11 @@ public void Run(TestConfig config)
root = new Root();
root.strIndex = db.CreateIndex<string, RecordFull>(IndexType.Unique);
root.longIndex = db.CreateIndex<long, RecordFull>(IndexType.Unique);
- root.thickByteIndex = db.CreateThickIndex<byte, RecordFull>();
db.Root = root;
var strIndex = root.strIndex;
Tests.Assert(typeof(string) == strIndex.KeyType);
var longIndex = root.longIndex;
Tests.Assert(typeof(long) == longIndex.KeyType);
- var thickByteIndex = root.thickByteIndex;
- Tests.Assert(typeof(byte) == thickByteIndex.KeyType);
DateTime start = DateTime.Now;
int startWithOne = 0;
int startWithFive = 0;
@@ -78,7 +60,6 @@ public void Run(TestConfig config)
string strLast = "0";
int n = 0;
- var inThickIndex = new Dictionary<byte, List<RecordFull>>();
foreach (var key in Tests.KeySeq(count))
{
RecordFull rec = new RecordFull(key);
@@ -92,29 +73,6 @@ public void Run(TestConfig config)
strLast = rec.StrVal;
longIndex[rec.Int32Val] = rec;
strIndex[rec.StrVal] = rec;
- if (n % 2 == 0)
- {
- thickByteIndex.Put(rec.ByteVal, rec);
- RememberInThick(inThickIndex, rec);
- }
- else
- {
- bool add = true;
- if (inThickIndex.ContainsKey(rec.ByteVal))
- {
- var list = inThickIndex[rec.ByteVal];
- var el = list[0];
- list.Remove(el);
- thickByteIndex.Remove(rec.ByteVal, el);
- if (list.Count > 0)
- add = false;
- }
- if (add)
- {
- RememberInThick(inThickIndex, rec);
- thickByteIndex[rec.ByteVal] = rec;
- }
- }
n++;
if (n % 100 == 0)
MyCommit(db, config.Serializable);
@@ -123,35 +81,18 @@ public void Run(TestConfig config)
Tests.Assert(longIndex.Count == count);
Tests.Assert(strIndex.Count == count);
- Tests.Assert(thickByteIndex.Count <= count);
res.InsertTime = DateTime.Now - start;
start = System.DateTime.Now;
- foreach (var mk in inThickIndex.Keys)
- {
- var list = inThickIndex[mk];
- while (list.Count > 1)
- {
- var el = list[0];
- list.Remove(el);
- thickByteIndex.Remove(el.ByteVal, el);
- }
- }
foreach (var key in Tests.KeySeq(count))
{
RecordFull rec1 = longIndex[key];
RecordFull rec2 = strIndex[Convert.ToString(key)];
- RecordFull rec3 = thickByteIndex[rec1.ByteVal];
- Tests.Assert(rec1 != null && rec2 != null && rec3 != null);
+ Tests.Assert(rec1 != null && rec2 != null);
Tests.Assert(rec1 == rec2);
- Tests.Assert(rec1.ByteVal == rec3.ByteVal);
}
res.IndexSearchTime = DateTime.Now - start;
- RecordFull[] recs = thickByteIndex.ToArray();
- Tests.Assert(recs.Length == thickByteIndex.Count);
- Array recs2 = thickByteIndex.ToArray(typeof(RecordFull));
- Tests.Assert(recs2.Length == recs.Length);
start = System.DateTime.Now;
var k = Int64.MinValue;
@@ -187,7 +128,7 @@ public void Run(TestConfig config)
Tests.AssertDatabaseException(() => longIndex.PrefixSearch("1"),
DatabaseException.ErrorCode.INCOMPATIBLE_KEY_TYPE);
- recs = strIndex.PrefixSearch("1");
+ RecordFull[] recs = strIndex.PrefixSearch("1");
Tests.Assert(startWithOne == recs.Length);
foreach (var r in recs)
{
@@ -228,7 +169,7 @@ public void Run(TestConfig config)
Tests.Assert(removed == rec);
strIndex.Remove(new Key(System.Convert.ToString(key)), rec);
}
- thickByteIndex.Clear();
+
res.RemoveTime = DateTime.Now - start;
db.Close();
if (config.IsTransient)
@@ -238,7 +179,6 @@ public void Run(TestConfig config)
root = (Root)db.Root;
longIndex = root.longIndex;
strIndex = root.strIndex;
- thickByteIndex = root.thickByteIndex;
k = Int64.MinValue;
n = 0;
RecordFull firstRec = null;
@@ -265,7 +205,6 @@ public void Run(TestConfig config)
Tests.Assert(!strIndex.Contains(notPresent));
Tests.Assert(!longIndex.Contains(notPresent));
longIndex.Clear();
- thickByteIndex.Clear();
Tests.Assert(!longIndex.Contains(firstRec));
db.Close();
}
1  csharp/tests/Tests/Tests.cs
View
@@ -569,6 +569,7 @@ public TestInfo(string name, TestConfig[] configs = null, int[] counts=null)
static TestInfo[] TestInfos = new TestInfo[]
{
+ new TestInfo("TestThickIndex"),
#if WITH_PATRICIA
new TestInfo("TestPatriciaTrie"),
#endif
1  csharp/tests/Tests/Tests.csproj
View
@@ -155,6 +155,7 @@
<Compile Include="TestRtree.cs" />
<Compile Include="Tests.cs" />
<Compile Include="TestSet.cs" />
+ <Compile Include="TestThickIndex.cs" />
<Compile Include="TestTimeSeries.cs" />
<Compile Include="TestTtree.cs" />
<Compile Include="TestXml.cs" />
6 csharp/todo.txt
View
@@ -7,13 +7,15 @@ Things to do for c# version:
* script that copies docs to my website (i.e. my blog repository)
* g+ button in the website version of docs
* more code coverage tests:
- * Relation
+ * Relation, RelationImpl
+ * TimeSeriesImpl
* Ttree
* TtreePage
* L2List
* L2ListElem
+ * PersistentCollection
+ * PersistentComparator
* Projection
- * Relation
* database corruption/recovery
* document setting IFile.NoFlush to true in performance_tuning.html
* make a reference API from .xml extracted during build process (after 0.9?)
Please sign in to comment.
Something went wrong with that request. Please try again.