Skip to content
This repository has been archived by the owner on Dec 30, 2020. It is now read-only.

Commit

Permalink
Fixed a read length bug in GridFS
Browse files Browse the repository at this point in the history
Renamed MapReduce result stats
  • Loading branch information
samus committed Feb 17, 2010
1 parent 7d63829 commit 335e5e3
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 7 deletions.
22 changes: 21 additions & 1 deletion MongoDB.GridFS.Tests/GridFileStreamTest.cs
Expand Up @@ -260,7 +260,27 @@ public class GridFileStreamTest
Assert.AreEqual(newsize, gfs.GridFileInfo.Length);
}


[Test]
public void TestReadLengthIsSameAsWriteLength(){
string filename = "readwritelength.txt";
GridFileStream gfs = fs.Create(filename);
int length = 0;
for(int i = 1; i <= 50; i++){
gfs.Write(BitConverter.GetBytes(i), 0, 4);
length += 4;
}
gfs.Close();
Assert.AreEqual(length, gfs.GridFileInfo.Length, "File length written is not the same as in gridfileinfo");

gfs = fs.OpenRead(filename);
byte[] buffer = new byte[16];
int read = 0;
int readLength = read;
while((read = gfs.Read(buffer,0,buffer.Length)) > 0){
readLength += read;
}
Assert.AreEqual(length, readLength, "Too much read back.");
}

#region File API compatibility

Expand Down
4 changes: 4 additions & 0 deletions MongoDB.GridFS/GridFileStream.cs
Expand Up @@ -108,6 +108,10 @@ public class GridFileStream : Stream
}else{
readCount = buffAvailable;
}
if(readCount + position > highestPosWritten){
//adjust readcount so that we don't read past the end of file.
readCount = readCount - (int)(readCount + position - highestPosWritten);
}
Array.Copy(buffer,buffPosition,array,offset,readCount);
buffPosition += readCount;
bytesLeftToRead -= readCount;
Expand Down
6 changes: 3 additions & 3 deletions MongoDB.Net-Tests/TestMapReduceBuilder.cs
Expand Up @@ -69,9 +69,9 @@ public class TestMapReduceBuilder
MapReduce mr = mrb.Map(mapfunction).Reduce(reducefunction).Execute();
Assert.IsNotNull(mr.Result);
Assert.IsTrue(mr.Result.Ok);
Assert.AreEqual(4, mr.Result.Input);
Assert.AreEqual(6, mr.Result.Emit);
Assert.AreEqual(3, mr.Result.Output);
Assert.AreEqual(4, mr.Result.InputCount);
Assert.AreEqual(6, mr.Result.EmitCount);
Assert.AreEqual(3, mr.Result.OutputCount);
}

[Test()]
Expand Down
2 changes: 2 additions & 0 deletions MongoDBDriver/CodeWScope.cs
Expand Up @@ -15,6 +15,8 @@ public class CodeWScope : Code

public CodeWScope(){}

public CodeWScope(String code):this(code, new Document()){}

public CodeWScope(String code, Document scope){
this.Value = code;
this.Scope = scope;
Expand Down
6 changes: 3 additions & 3 deletions MongoDBDriver/MapReduce.cs
Expand Up @@ -21,15 +21,15 @@ public class MapReduceResult{
public string CollectionName{
get{return (string)result["result"];}
}
public long Input{
public long InputCount{
get{return Convert.ToInt64(counts["input"]);}
}

public long Emit{
public long EmitCount{
get{return Convert.ToInt64(counts["emit"]);}
}

public long Output{
public long OutputCount{
get{return Convert.ToInt64(counts["output"]);}
}

Expand Down

0 comments on commit 335e5e3

Please sign in to comment.