Example #1
0
		protected virtual void TstDeletion()
		{
			A().Provider().StoreNew(new Pilot("Pilot1", 42));
			Pilot o = new Pilot("Pilot2", 43);
			A().Provider().StoreNew(o);
			A().Provider().Commit();
			A().Provider().StoreNew(new Pilot("Pilot3", 44));
			A().Provider().Delete(FindPilot("Pilot1"));
			Car car = new Car("Car1");
			car.SetPilot(FindPilot("Pilot2"));
			A().Provider().StoreNew(car);
			A().Provider().Commit();
			StartReplication();
			IDrsUUID uuidCar1 = Uuid(FindCar("Car1"));
			Assert.IsNotNull(uuidCar1);
			A().Provider().ReplicateDeletion(uuidCar1);
			CommitReplication();
			Assert.IsNull(FindCar("Car1"));
			StartReplication();
			IDrsUUID uuidPilot2 = Uuid(FindPilot("Pilot2"));
			Assert.IsNotNull(uuidPilot2);
			A().Provider().ReplicateDeletion(uuidPilot2);
			CommitReplication();
			Assert.IsNull(FindPilot("Pilot2"));
		}
Example #2
0
		public virtual void Test()
		{
			ITestableReplicationProviderInside providerA = A().Provider();
			ITestableReplicationProviderInside providerB = B().Provider();
			providerA.StoreNew(new Pilot());
			providerA.Commit();
			IReplicationSession replication = Replication.Begin(providerA, providerB, null, _fixtures
				.reflector);
			TimeStamps initialTimeStampsB = AssertTimeStampsForFirstReplication(providerB);
			IObjectSet modifiedObjects = providerA.ObjectsChangedSinceLastReplication();
			while (modifiedObjects.HasNext())
			{
				replication.Replicate(modifiedObjects.Next());
			}
			replication.Commit();
			Pilot replicatedPilot = (Pilot)providerB.GetStoredObjects(typeof(Pilot)).Next();
			long version = providerB.ObjectVersion(replicatedPilot);
			Assert.AreEqual(initialTimeStampsB.Commit(), version);
			replication = Replication.Begin(providerA, providerB, null, _fixtures.reflector);
			TimeStamps timestampsBAfterReplication = AssertTimeStampsForSecondReplication(initialTimeStampsB
				, providerB);
			replication.Commit();
			Pilot pilotStoredAfterReplication = new Pilot();
			providerB.StoreNew(pilotStoredAfterReplication);
			providerB.Commit();
			providerB.WaitForPreviousCommits();
			version = providerB.ObjectVersion(pilotStoredAfterReplication);
			Assert.IsGreater(timestampsBAfterReplication.Commit(), version);
		}
		private void StoreNewPilotIn(ITestableReplicationProviderInside provider)
		{
			Pilot pilot = new Pilot();
			provider.StoreNew(pilot);
			provider.Commit();
			provider.WaitForPreviousCommits();
		}
		public virtual void Test()
		{
			Pilot pilot = new Pilot("one", 1);
			A().Provider().StoreNew(pilot);
			A().Provider().Commit();
			ReplicateAll(A().Provider(), B().Provider(), null);
			pilot.SetName("modified");
			A().Provider().Update(pilot);
			A().Provider().Commit();
			ReplicateAll(A().Provider(), B().Provider(), null);
			Pilot pilotFromB = (Pilot)GetOneInstance(B(), typeof(Pilot));
			Assert.AreEqual("modified", pilotFromB.Name());
		}
Example #5
0
		public virtual void SetPilot(Pilot newPilot)
		{
			_pilot = newPilot;
		}
Example #6
0
		private void TstStore()
		{
			StartReplication();
			Pilot object1 = new Pilot("John Cleese", 42);
			IDrsUUID uuid = new DrsUUIDImpl(new Db4oUUID(15, BSignatureBytes));
			IReplicationReference @ref = new ReplicationReferenceImpl("ignoredSinceInOtherProvider"
				, uuid, 1);
			A().Provider().ReferenceNewObject(object1, @ref, null, null);
			A().Provider().StoreReplica(object1);
			IReplicationReference reference = A().Provider().ProduceReferenceByUUID(uuid, object1
				.GetType());
			Assert.AreEqual(reference, A().Provider().ProduceReference(object1, null, null));
			Assert.AreEqual(object1, reference.Object());
			CommitReplication();
			StartReplication();
			IEnumerator storedObjects = A().Provider().GetStoredObjects(typeof(Pilot)).GetEnumerator
				();
			Pilot reloaded = (Pilot)Next(storedObjects);
			Assert.IsFalse(storedObjects.MoveNext());
			reference = A().Provider().ProduceReferenceByUUID(uuid, object1.GetType());
			Assert.AreEqual(reference, A().Provider().ProduceReference(reloaded, null, null));
			reloaded.SetName("i am updated");
			A().Provider().StoreReplica(reloaded);
			A().Provider().ClearAllReferences();
			CommitReplication();
			StartReplication();
			reference = A().Provider().ProduceReferenceByUUID(uuid, reloaded.GetType());
			Assert.AreEqual("i am updated", ((Pilot)reference.Object()).Name());
			CommitReplication();
			A().Provider().DeleteAllInstances(typeof(Pilot));
			A().Provider().Commit();
		}
Example #7
0
		private void TstRollback()
		{
			if (!A().Provider().SupportsRollback())
			{
				return;
			}
			if (!B().Provider().SupportsRollback())
			{
				return;
			}
			StartReplication();
			Pilot object1 = new Pilot("Albert Kwan", 25);
			IDrsUUID uuid = new DrsUUIDImpl(new Db4oUUID(5678, BSignatureBytes));
			IReplicationReference @ref = new ReplicationReferenceImpl(object1, uuid, 1);
			A().Provider().ReferenceNewObject(object1, @ref, null, null);
			A().Provider().StoreReplica(object1);
			Assert.IsFalse(A().Provider().WasModifiedSinceLastReplication(@ref));
			A().Provider().RollbackReplication();
			A().Provider().StartReplicationTransaction(BSignature);
			Assert.IsNull(A().Provider().ProduceReference(object1, null, null));
			IReplicationReference byUUID = A().Provider().ProduceReferenceByUUID(uuid, object1
				.GetType());
			Assert.IsNull(byUUID);
			A().Provider().RollbackReplication();
			B().Provider().RollbackReplication();
		}
Example #8
0
		private void TstReferences()
		{
			Pilot pilot = new Pilot("tst References", 42);
			A().Provider().StoreNew(pilot);
			A().Provider().Commit();
			StartReplication();
			Pilot object1 = (Pilot)Next(A().Provider().GetStoredObjects(typeof(Pilot)).GetEnumerator
				());
			IReplicationReference reference = A().Provider().ProduceReference(object1, null, 
				null);
			Assert.AreEqual(object1, reference.Object());
			IDrsUUID uuid = reference.Uuid();
			IReplicationReference ref2 = A().Provider().ProduceReferenceByUUID(uuid, typeof(Pilot
				));
			Assert.AreEqual(reference, ref2);
			A().Provider().ClearAllReferences();
			IDrsUUID db4oUUID = A().Provider().ProduceReference(object1, null, null).Uuid();
			Assert.AreEqual(uuid, db4oUUID);
			CommitReplication();
			A().Provider().DeleteAllInstances(typeof(Pilot));
			A().Provider().Commit();
		}
Example #9
0
		private void TstObjectsChangedSinceLastReplication()
		{
			Pilot object1 = new Pilot("John Cleese", 42);
			Pilot object2 = new Pilot("Terry Gilliam", 53);
			Car object3 = new Car("Volvo");
			A().Provider().StoreNew(object1);
			A().Provider().StoreNew(object2);
			A().Provider().StoreNew(object3);
			A().Provider().Commit();
			StartReplication();
			IObjectSet changed = A().Provider().ObjectsChangedSinceLastReplication();
			Assert.AreEqual(3, changed.Count);
			IObjectSet os = A().Provider().ObjectsChangedSinceLastReplication(typeof(Pilot));
			Assert.AreEqual(2, os.Count);
			IEnumerator pilots = os.GetEnumerator();
			//		Assert.isTrue(pilots.contains(findPilot("John Cleese")));
			//	Assert.isTrue(pilots.contains(findPilot("Terry Gilliam")));
			IEnumerator cars = A().Provider().ObjectsChangedSinceLastReplication(typeof(Car))
				.GetEnumerator();
			Assert.AreEqual("Volvo", ((Car)Next(cars)).GetModel());
			Assert.IsFalse(cars.MoveNext());
			CommitReplication();
			StartReplication();
			Assert.IsFalse(A().Provider().ObjectsChangedSinceLastReplication().GetEnumerator(
				).MoveNext());
			CommitReplication();
			Pilot pilot = (Pilot)Next(A().Provider().GetStoredObjects(typeof(Pilot)).GetEnumerator
				());
			pilot.SetName("Terry Jones");
			Car car = (Car)Next(A().Provider().GetStoredObjects(typeof(Car)).GetEnumerator());
			car.SetModel("McLaren");
			A().Provider().Update(pilot);
			A().Provider().Update(car);
			A().Provider().Commit();
			StartReplication();
			Assert.AreEqual(2, A().Provider().ObjectsChangedSinceLastReplication().Count);
			pilots = A().Provider().ObjectsChangedSinceLastReplication(typeof(Pilot)).GetEnumerator
				();
			Assert.AreEqual("Terry Jones", ((Pilot)Next(pilots)).Name());
			Assert.IsFalse(pilots.MoveNext());
			cars = A().Provider().ObjectsChangedSinceLastReplication(typeof(Car)).GetEnumerator
				();
			Assert.AreEqual("McLaren", ((Car)Next(cars)).GetModel());
			Assert.IsFalse(cars.MoveNext());
			CommitReplication();
			A().Provider().DeleteAllInstances(typeof(Pilot));
			A().Provider().DeleteAllInstances(typeof(Car));
			A().Provider().Commit();
		}
Example #10
0
 public virtual void SetPilot(Pilot newPilot)
 {
     _pilot = newPilot;
 }