Permalink
Browse files

Merge with samus/pool.

  • Loading branch information...
2 parents 19c456f + ce25cb5 commit 5d502a0357724c6c08c99902829bedd79695ce0a @lanwin lanwin committed Mar 8, 2010
Showing with 1,361 additions and 723 deletions.
  1. +3 −0 .gitignore
  2. +27 −51 MongoDB.GridFS.Tests/GridFileInfoTest.cs
  3. +22 −41 MongoDB.GridFS.Tests/GridFileStreamTest.cs
  4. +11 −37 MongoDB.GridFS.Tests/GridFileTest.cs
  5. +39 −0 MongoDB.GridFS.Tests/GridTestBase.cs
  6. +10 −0 MongoDB.GridFS.Tests/MongoDB.GridFS.Tests.csproj
  7. +6 −0 MongoDB.GridFS.Tests/MongoDB.GridFS.Tests.dll.config
  8. +28 −1 MongoDB.Net-Tests/Bson/TestRoundTrips.cs
  9. +202 −0 MongoDB.Net-Tests/Connections/TestPooledConnectionFactory.cs
  10. +4 −1 MongoDB.Net-Tests/MongoDB.Driver.Tests.csproj
  11. +6 −0 MongoDB.Net-Tests/MongoDB.Driver.Tests.dll.config
  12. +23 −3 MongoDB.Net-Tests/MongoTestBase.cs
  13. +106 −109 MongoDB.Net-Tests/TestCollection.cs
  14. +50 −40 MongoDB.Net-Tests/TestCollectionMetaData.cs
  15. +25 −28 MongoDB.Net-Tests/TestConcurrency.cs
  16. +28 −30 MongoDB.Net-Tests/TestCursor.cs
  17. +37 −46 MongoDB.Net-Tests/TestDatabase.cs
  18. +20 −26 MongoDB.Net-Tests/TestDatabaseJS.cs
  19. +21 −38 MongoDB.Net-Tests/TestDatabaseMetaData.cs
  20. +17 −31 MongoDB.Net-Tests/TestMapReduce.cs
  21. +18 −36 MongoDB.Net-Tests/TestMapReduceBuilder.cs
  22. +5 −7 MongoDB.Net-Tests/TestMongo.cs
  23. +0 −17 MongoDB.Net-Tests/TestMongoExceptions.cs
  24. +1 −1 MongoDB.Net-Tests/Util/TestJsonUtils.cs
  25. +17 −4 MongoDBDriver.sln
  26. +21 −19 MongoDBDriver/Bson/BsonReader.cs
  27. +1 −1 MongoDBDriver/Code.cs
  28. +63 −46 MongoDBDriver/CollectionMetaData.cs
  29. +13 −0 MongoDBDriver/Connections/IConnectionFactory.cs
  30. +261 −0 MongoDBDriver/Connections/PooledConnectionFactory.cs
  31. +7 −0 MongoDBDriver/Database.cs
  32. +47 −44 MongoDBDriver/MongoConnectionStringBuilder.cs
  33. +1 −1 MongoDBDriver/MongoDB.Driver.csproj
  34. +1 −1 MongoDBDriver/MongoMaxKey.cs
  35. +1 −1 MongoDBDriver/MongoMinKey.cs
  36. +27 −24 MongoDBDriver/Util/JsonFormatter.cs
  37. +0 −15 MongoDBDriverTranslation/MongoDBDriverTranslation.mdproj
  38. +0 −12 MongoDBDriverTranslation/en.po
  39. +0 −12 MongoDBDriverTranslation/messages.po
  40. +26 −0 examples/Simple/AssemblyInfo.cs
  41. +99 −0 examples/Simple/Main.cs
  42. +51 −0 examples/Simple/Simple.csproj
  43. +6 −0 examples/Simple/Simple.exe.config
  44. +10 −0 examples/Simple/obj/Debug/Simple.csproj.FileListAbsolute.txt
  45. BIN examples/Simple/obj/Debug/Simple.exe
View
@@ -21,6 +21,9 @@
*/test-results/*
/test-results/
+/examples/*/bin/*
+/examples/*/test-results/*
+
/_UpgradeReport_Files/*
/redist/*.zip
@@ -8,14 +8,21 @@
namespace MongoDB.GridFS
{
[TestFixture]
- public class GridFileInfoTest
+ public class GridFileInfoTest : GridTestBase
{
- Mongo db = new Mongo();
+
+ public override string TestFileSystems {
+ get {
+ return "gfcreate,gfdelete,gfmove,gfopen,gfexists,gfinfo";
+ }
+ }
+
+
[Test]
public void TestCreateNonExisting(){
String filename = "newfile.txt";
- GridFile gf = new GridFile(db["tests"],"gfcreate");
- GridFileInfo gfi = new GridFileInfo(db["tests"],"gfcreate", filename);
+ GridFile gf = new GridFile(DB,"gfcreate");
+ GridFileInfo gfi = new GridFileInfo(DB,"gfcreate", filename);
Assert.AreEqual(filename, gfi.FileName);
GridFileStream gfs = gfi.Create();
@@ -26,12 +33,14 @@ public class GridFileInfoTest
[Test]
public void TestCreateExisting(){
String filename = "existing.txt";
- GridFile gf = new GridFile(db["tests"],"gfcreate");
- GridFileInfo gfi = new GridFileInfo(db["tests"],"gfcreate", filename);
+ GridFile gf = new GridFile(DB,"gfcreate");
+ GridFileInfo gfi = new GridFileInfo(DB,"gfcreate", filename);
GridFileStream gfs = gfi.Create();
+ gfs.Close();
+
bool thrown = false;
try{
- gfi = new GridFileInfo(db["tests"],"create", filename);
+ gfi = new GridFileInfo(DB,"gfcreate", filename);
gfi.Create();
}catch(IOException){
thrown = true;
@@ -43,7 +52,7 @@ public class GridFileInfoTest
public void TestModeCreateNew(){
Object id;
string filename = "createnew.txt";
- GridFileInfo gfi = new GridFileInfo(db["tests"],"gfcreate", filename);
+ GridFileInfo gfi = new GridFileInfo(DB,"gfcreate", filename);
using(GridFileStream gfs = gfi.Create(FileMode.CreateNew)){
id = gfs.GridFileInfo.Id;
TextWriter tw = new StreamWriter(gfs);
@@ -56,8 +65,8 @@ public class GridFileInfoTest
[Test]
public void TestDelete(){
String filename = "gfi-delete.txt";
- GridFile gf = new GridFile(db["tests"],"gfdelete");
- GridFileInfo gfi = new GridFileInfo(db["tests"],"gfdelete", filename);
+ GridFile gf = new GridFile(DB,"gfdelete");
+ GridFileInfo gfi = new GridFileInfo(DB,"gfdelete", filename);
GridFileStream gfs = gfi.Create(); //TODO Expand Test to make sure that chunks for the file got deleted too.
gfi.Delete();
Assert.IsFalse(gf.Exists(filename), "File should have been deleted.");
@@ -67,8 +76,8 @@ public class GridFileInfoTest
public void TestMoveTo(){
String filename = "gfi-move.txt";
String filename2 = "gfi-move.txt2";
- GridFile gf = new GridFile(db["tests"],"gfmove");
- GridFileInfo gfi = new GridFileInfo(db["tests"],"gfmove", filename);
+ GridFile gf = new GridFile(DB,"gfmove");
+ GridFileInfo gfi = new GridFileInfo(DB,"gfmove", filename);
gfi.Create();
gfi.MoveTo(filename2);
Assert.IsFalse(gf.Exists(filename), "File should have been moved.");
@@ -79,7 +88,7 @@ public class GridFileInfoTest
[Test]
public void TestFileExists(){
string filename = "gfi-exists.txt";
- GridFileInfo gfi = new GridFileInfo(db["tests"], "gfexists", filename);
+ GridFileInfo gfi = new GridFileInfo(DB, "gfexists", filename);
Assert.IsFalse(gfi.Exists);
GridFileStream gfs = gfi.Create();
Assert.IsTrue(gfi.Exists);
@@ -88,8 +97,8 @@ public class GridFileInfoTest
[Test]
public void TestOpenNonExistentFails(){
string filename = "gfi-opennothere.txt";
- GridFile gf = new GridFile(db["tests"], "gfopen");
- GridFileInfo gfi = new GridFileInfo(db["tests"], "gfopen", filename);
+ GridFile gf = new GridFile(DB, "gfopen");
+ GridFileInfo gfi = new GridFileInfo(DB, "gfopen", filename);
bool thrown = false;
try{
GridFileStream gfs = gfi.OpenRead();
@@ -103,7 +112,7 @@ public class GridFileInfoTest
[Test]
public void TestOpenReadOnly(){
string filename = "gfi-open.txt";
- GridFile gf = new GridFile(db["tests"], "gfopen");
+ GridFile gf = new GridFile(DB, "gfopen");
GridFileStream gfs = gf.Create(filename);
gfs.Close();
@@ -126,7 +135,7 @@ public class GridFileInfoTest
string fs = "gfinfo";
Object id;
- GridFileInfo gfi = new GridFileInfo(db["tests"],fs, filename);
+ GridFileInfo gfi = new GridFileInfo(DB,fs, filename);
using(GridFileStream gfs = gfi.Create(FileMode.CreateNew)){
id = gfs.GridFileInfo.Id;
gfi.ContentType = "text/sam";
@@ -136,46 +145,13 @@ public class GridFileInfoTest
tw.Close();
}
gfi.Aliases = new String[]{"file1"};
- GridFileInfo gfi2 = new GridFileInfo(db["tests"],fs, filename);
+ GridFileInfo gfi2 = new GridFileInfo(DB,fs, filename);
Assert.IsTrue(gfi2.Exists, "Couldn't find " + filename);
Assert.AreEqual("text/sam", gfi2.ContentType);
Assert.AreNotEqual(gfi2.Aliases, gfi.Aliases);
gfi.UpdateInfo();
gfi2.Refresh();
Assert.AreEqual(gfi2.Aliases, gfi.Aliases);
- }
-
- [TestFixtureSetUp]
- public void Init(){
- db.Connect();
- CleanDB(); //Run here instead of at the end so that the db can be examined after a run.
- }
-
- [TestFixtureTearDown]
- public void Dispose(){
- db.Disconnect();
- }
-
- protected void CleanDB(){
- //Any collections that we might want to delete before the tests run should be done here.
- DropGridFileSystem("gfcreate");
- DropGridFileSystem("gfdelete");
- DropGridFileSystem("gfmove");
- DropGridFileSystem("gfopen");
- DropGridFileSystem("gfexists");
- DropGridFileSystem("gfinfo");
- }
-
- protected void DropGridFileSystem(string filesystem){
- try{
- db["tests"].MetaData.DropCollection(filesystem + ".files");
- db["tests"].MetaData.DropCollection(filesystem + ".chunks");
- }catch(MongoCommandException){}//if it fails it is because the collection isn't there to start with.
-
- }
-
- protected long CountChunks(string filesystem, Object fileid){
- return db["tests"][filesystem + ".chunks"].Count(new Document().Append("files_id", fileid));
}
}
}
@@ -8,12 +8,22 @@
namespace MongoDB.GridFS
{
[TestFixture]
- public class GridFileStreamTest
+ public class GridFileStreamTest : GridTestBase
{
- Mongo db = new Mongo();
GridFile fs;
String filesystem = "gfstream";
+ public override string TestFileSystems {
+ get {
+ return filesystem;
+ }
+ }
+
+ public override void OnInit (){
+ fs = new GridFile(DB, filesystem);
+ }
+
+
[Test]
public void TestWrite(){
@@ -25,7 +35,7 @@ public class GridFileStreamTest
}
gfs.Close();
- Assert.AreEqual(1, CountChunks(id));
+ Assert.AreEqual(1, CountChunks(filesystem,id));
Document chunk = GrabChunk(id, 0);
Binary bin = (Binary)chunk["data"];
Assert.AreEqual(127, bin.Bytes[127]);
@@ -42,7 +52,7 @@ public class GridFileStreamTest
}
gfs.Close();
- Assert.AreEqual(1, CountChunks(id));
+ Assert.AreEqual(1, CountChunks(filesystem,id));
}
[Test]
@@ -56,7 +66,7 @@ public class GridFileStreamTest
gfs.Write(buff,0,buff.Length);
Assert.AreEqual(buff.Length, gfs.Position);
gfs.Close();
- Assert.AreEqual(chunks, CountChunks(id));
+ Assert.AreEqual(chunks, CountChunks(filesystem,id));
}
[Test]
@@ -99,7 +109,7 @@ public class GridFileStreamTest
int size = chunks * chunksize;
Object id = CreateDummyFile(filename, size, chunksize, offset);
- Assert.AreEqual(2, CountChunks(id));
+ Assert.AreEqual(2, CountChunks(filesystem,id));
GridFileStream gfs = fs.OpenRead(filename);
byte[] buff = new Byte[4];
@@ -134,7 +144,7 @@ public class GridFileStreamTest
}
gfs.Close();
- Assert.AreEqual(1, CountChunks(id));
+ Assert.AreEqual(1, CountChunks(filesystem,id));
Document chunk = GrabChunk(id, 0);
Binary b = (Binary)chunk["data"];
Assert.AreEqual(2, b.Bytes[chunksize-1]);
@@ -179,7 +189,7 @@ public class GridFileStreamTest
}
Assert.AreEqual(buffsize, gfs.Position, "Position is incorrect");
gfs.Close();
- Assert.AreEqual(chunks - 1, CountChunks(id));
+ Assert.AreEqual(chunks - 1, CountChunks(filesystem,id));
Document chunk = GrabChunk(id, 0);
Binary b = (Binary)chunk["data"];
Assert.AreEqual(2, b.Bytes[buffsize-1]);
@@ -238,10 +248,10 @@ public class GridFileStreamTest
gfs.SetLength(length);
gfs.WriteByte(2);
gfs.Close();
- GridFileInfo gfi = new GridFileInfo(db["tests"],filesystem,filename);
+ GridFileInfo gfi = new GridFileInfo(DB,filesystem,filename);
Assert.AreEqual(length + 1, gfi.Length);
- Assert.AreEqual(6, CountChunks(id));
+ Assert.AreEqual(6, CountChunks(filesystem,id));
}
@@ -308,41 +318,12 @@ public class GridFileStreamTest
#endregion
- [TestFixtureSetUp]
- public void Init(){
- db.Connect();
- fs = new GridFile(db["tests"], filesystem);
- CleanDB(); //Run here instead of at the end so that the db can be examined after a run.
- }
-
- [TestFixtureTearDown]
- public void Dispose(){
- db.Disconnect();
- }
-
- protected void CleanDB(){
- //Any collections that we might want to delete before the tests run should be done here.
- DropGridFileSystem(filesystem);
- }
-
- protected void DropGridFileSystem(string filesystem){
- try{
- db["tests"].MetaData.DropCollection(filesystem + ".files");
- db["tests"].MetaData.DropCollection(filesystem + ".chunks");
- }catch(MongoCommandException){}//if it fails it is because the collection isn't there to start with.
-
- }
-
- protected long CountChunks(Object fileid){
- return db["tests"][filesystem + ".chunks"].Count(new Document().Append("files_id", fileid));
- }
-
protected Document GrabChunk(Object fileid, int chunk){
- return db["tests"][filesystem + ".chunks"].FindOne(new Document().Append("files_id", fileid).Append("n", chunk));
+ return DB[filesystem + ".chunks"].FindOne(new Document().Append("files_id", fileid).Append("n", chunk));
}
protected Object CreateDummyFile(string filename, int size, int chunksize, int initialOffset){
- GridFileInfo gfi = new GridFileInfo(db["tests"], "gfstream", filename);
+ GridFileInfo gfi = new GridFileInfo(DB, "gfstream", filename);
gfi.ChunkSize = chunksize;
GridFileStream gfs = gfi.Create();
Object id = gfs.GridFileInfo.Id;
@@ -8,24 +8,29 @@
namespace MongoDB.GridFS
{
[TestFixture]
- public class GridFileTest{
- Mongo db = new Mongo();
+ public class GridFileTest : GridTestBase
+ {
+ public override string TestFileSystems {
+ get {
+ return "gfcopy,gfcreate,fs";
+ }
+ }
[Test]
public void TestFileDoesNotExist(){
- GridFile fs = new GridFile(db["tests"]);
+ GridFile fs = new GridFile(DB);
Assert.IsFalse(fs.Exists("non-existent filename"));
}
[Test]
public void TestFileDoes(){
- GridFile fs = new GridFile(db["tests"]);
+ GridFile fs = new GridFile(DB);
fs.Create("exists.txt");
Assert.IsTrue(fs.Exists("exists.txt"));
}
[Test]
public void TestCopy(){
- GridFile fs = new GridFile(db["tests"], "gfcopy");
+ GridFile fs = new GridFile(DB, "gfcopy");
GridFileStream gfs = fs.Create("original.txt");
gfs.WriteByte(1);
gfs.Seek(1024 * 256 * 2, SeekOrigin.Begin);
@@ -41,45 +46,14 @@ public class GridFileTest{
public void TestModeCreateNew(){
Object id;
string filename = "createnew.txt";
- GridFile gf = new GridFile(db["tests"],"gfcreate");
+ GridFile gf = new GridFile(DB,"gfcreate");
using(GridFileStream gfs = gf.Create(filename, FileMode.CreateNew)){
id = gfs.GridFileInfo.Id;
TextWriter tw = new StreamWriter(gfs);
tw.WriteLine("test");
tw.Close();
}
Assert.AreEqual(1, CountChunks("gfcreate", id));
- }
-
- [TestFixtureSetUp]
- public void Init(){
- db.Connect();
- CleanDB(); //Run here instead of at the end so that the db can be examined after a run.
- }
-
- [TestFixtureTearDown]
- public void Dispose(){
- db.Disconnect();
- }
-
- protected void CleanDB(){
- //Any collections that we might want to delete before the tests run should be done here.
- DropGridFileSystem("gfcopy");
- DropGridFileSystem("gfcreate");
- DropGridFileSystem("fs");
- }
-
- protected void DropGridFileSystem(string filesystem){
- try{
- db["tests"].MetaData.DropCollection(filesystem + ".files");
- db["tests"].MetaData.DropCollection(filesystem + ".chunks");
- }catch(MongoCommandException){}//if it fails it is because the collection isn't there to start with.
-
- }
-
- protected long CountChunks(string filesystem, Object fileid){
- return db["tests"][filesystem + ".chunks"].Count(new Document().Append("files_id", fileid));
}
-
}
}
Oops, something went wrong.

0 comments on commit 5d502a0

Please sign in to comment.