2
using System.Collections;
4
using System.Threading;
12
namespace Simias.Storage.Tests
15
/// Test cases for Iteration 0 stories.
18
public class ChangeLogTests
21
// Object used to access the store.
22
private Store store = null;
25
private string basePath = Path.Combine( Directory.GetCurrentDirectory(), "CollectionStoreTestDir" );
26
private Manager manager;
31
/// Performs pre-initialization tasks.
36
Configuration config = Configuration.CreateDefaultConfig( basePath );
38
manager = new Manager( config );
39
manager.StartServices();
40
manager.WaitForServicesStarted();
42
// Connect to the store.
43
store = Store.GetStore();
47
#region Iteration Tests
49
/// Creates objects in a collection and verifies that the log file changes are being seen.
54
// Create a new collection and remember its ID.
55
Collection collection = new Collection( store, "CS_TestCollection", store.DefaultDomain);
59
// Commit the collection.
62
// Create a change log reader.
63
ChangeLogReader logReader = new ChangeLogReader( collection );
65
// Get a cookie to track the event changes that we've seen.
66
EventContext eventCookie = logReader.GetEventContext();
68
// Now start creating a bunch of collection events.
69
Node[] nodeList = new Node[ 100 ];
70
for( int i = 0; i < 100; ++i )
72
nodeList[ i ] = new Node( "CS_TestNode-" + i );
75
// Commit the changes.
76
collection.Commit( nodeList );
78
// Now get the events that have been generated.
80
bool moreData = logReader.GetEvents( eventCookie, out changeList );
82
foreach( ChangeLogRecord rec in changeList )
84
Console.WriteLine( "Found change: Record ID: {0}, TimeStamp: {1}, Operation: {2}, Node ID: {3}", rec.RecordID, rec.Epoch, rec.Operation, rec.EventID );
87
// Delete all of the node objects.
88
collection.Commit( collection.Delete( nodeList ) );
90
// Get the delete events.
91
moreData = logReader.GetEvents( eventCookie, out changeList );
93
foreach( ChangeLogRecord rec in changeList )
95
Console.WriteLine( "Found change: Record ID: {0}, TimeStamp: {1}, Operation: {2}, Node ID: {3}", rec.RecordID, rec.Epoch, rec.Operation, rec.EventID );
100
// Delete the collection.
101
collection.Commit( collection.Delete() );
106
#region Test Clean Up
108
/// Clean up for tests.
110
[TestFixtureTearDown]
111
public void Cleanup()
113
// Delete the database. Must be store owner to delete the database.
116
manager.StopServices();
117
manager.WaitForServicesStopped();
119
// Remove the created directory.
120
string dirPath = Path.Combine( Directory.GetCurrentDirectory(), "CollectionStoreTestDir" );
121
if ( Directory.Exists( dirPath ) )
123
// Directory.Delete( dirPath, true );