~ifolder-dev/simias/trunk-packaging

« back to all changes in this revision

Viewing changes to src/core/ChangeLog/.svn/text-base/ChangeLogTests.cs.svn-base

  • Committer: Jorge O. Castro
  • Date: 2007-12-03 06:56:46 UTC
  • Revision ID: jorge@ubuntu.com-20071203065646-mupcnjcwgm5mnhyt
* Remove a bunch of .svn directories we no longer need.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
using System;
2
 
using System.Collections;
3
 
using System.IO;
4
 
using System.Threading;
5
 
 
6
 
using Simias;
7
 
using Simias.Service;
8
 
using NUnit.Framework;
9
 
 
10
 
using Simias.Storage;
11
 
 
12
 
namespace Simias.Storage.Tests
13
 
{
14
 
        /// <summary>
15
 
        /// Test cases for Iteration 0 stories.
16
 
        /// </summary>
17
 
        [TestFixture]
18
 
        public class ChangeLogTests
19
 
        {
20
 
                #region Class Members
21
 
                // Object used to access the store.
22
 
                private Store store = null;
23
 
 
24
 
                // Path to store.
25
 
                private string basePath = Path.Combine( Directory.GetCurrentDirectory(), "CollectionStoreTestDir" );
26
 
                private Manager manager;
27
 
                #endregion
28
 
 
29
 
                #region Test Setup
30
 
                /// <summary>
31
 
                /// Performs pre-initialization tasks.
32
 
                /// </summary>
33
 
                [TestFixtureSetUp]
34
 
                public void Init()
35
 
                {
36
 
                        Configuration config = Configuration.CreateDefaultConfig( basePath );
37
 
 
38
 
                        manager = new Manager( config );
39
 
                        manager.StartServices();
40
 
                        manager.WaitForServicesStarted();
41
 
 
42
 
                        // Connect to the store.
43
 
                        store = Store.GetStore();
44
 
                }
45
 
                #endregion
46
 
 
47
 
                #region Iteration Tests
48
 
                /// <summary>
49
 
                /// Creates objects in a collection and verifies that the log file changes are being seen.
50
 
                /// </summary>
51
 
                [Test]
52
 
                public void Test1()
53
 
                {
54
 
                        // Create a new collection and remember its ID.
55
 
                        Collection collection = new Collection( store, "CS_TestCollection", store.DefaultDomain);
56
 
 
57
 
                        try
58
 
                        {
59
 
                                // Commit the collection.
60
 
                                collection.Commit();
61
 
 
62
 
                                // Create a change log reader.
63
 
                                ChangeLogReader logReader = new ChangeLogReader( collection );
64
 
                                
65
 
                                // Get a cookie to track the event changes that we've seen.
66
 
                                EventContext eventCookie = logReader.GetEventContext();
67
 
 
68
 
                                // Now start creating a bunch of collection events.
69
 
                                Node[] nodeList = new Node[ 100 ];
70
 
                                for( int i = 0; i < 100; ++i )
71
 
                                {
72
 
                                        nodeList[ i ] = new Node( "CS_TestNode-" + i );
73
 
                                }
74
 
 
75
 
                                // Commit the changes.
76
 
                                collection.Commit( nodeList );
77
 
 
78
 
                                // Now get the events that have been generated.
79
 
                                ArrayList changeList;
80
 
                                bool moreData = logReader.GetEvents( eventCookie, out changeList );
81
 
 
82
 
                                foreach( ChangeLogRecord rec in changeList )
83
 
                                {
84
 
                                        Console.WriteLine( "Found change: Record ID: {0}, TimeStamp: {1}, Operation: {2}, Node ID: {3}", rec.RecordID, rec.Epoch, rec.Operation, rec.EventID );
85
 
                                }
86
 
 
87
 
                                // Delete all of the node objects.
88
 
                                collection.Commit( collection.Delete( nodeList ) );
89
 
 
90
 
                                // Get the delete events.
91
 
                                moreData = logReader.GetEvents( eventCookie, out changeList );
92
 
 
93
 
                                foreach( ChangeLogRecord rec in changeList )
94
 
                                {
95
 
                                        Console.WriteLine( "Found change: Record ID: {0}, TimeStamp: {1}, Operation: {2}, Node ID: {3}", rec.RecordID, rec.Epoch, rec.Operation, rec.EventID );
96
 
                                }
97
 
                        }
98
 
                        finally
99
 
                        {
100
 
                                // Delete the collection.
101
 
                                collection.Commit( collection.Delete() );
102
 
                        }
103
 
                }
104
 
                #endregion
105
 
 
106
 
                #region Test Clean Up
107
 
                /// <summary>
108
 
                /// Clean up for tests.
109
 
                /// </summary>
110
 
                [TestFixtureTearDown]
111
 
                public void Cleanup()
112
 
                {
113
 
                        // Delete the database.  Must be store owner to delete the database.
114
 
                        store.Delete();
115
 
 
116
 
                        manager.StopServices();
117
 
                        manager.WaitForServicesStopped();
118
 
 
119
 
                        // Remove the created directory.
120
 
                        string dirPath = Path.Combine( Directory.GetCurrentDirectory(), "CollectionStoreTestDir" );
121
 
                        if ( Directory.Exists( dirPath ) )
122
 
                        {
123
 
//                              Directory.Delete( dirPath, true );
124
 
                        }
125
 
                }
126
 
                #endregion
127
 
        }
128
 
}