Esempio n. 1
0
        public void Push_2DifferentApiServers_HgRepoFileUpdatedWithBothEntries()
        {
            using (var e1 = new TestEnvironment("api1", ApiServerType.Dummy))
                using (var provider = GetTransportProviderForTest(e1))
                {
                    var api2       = new DummyApiServerForTest("api3");
                    var transport2 = new HgResumeTransport(e1.Local.Repository, "api3", api2, e1.MultiProgress);

                    // push to ApiServer 1
                    e1.LocalAddAndCommit();
                    var revisionResponse = ApiResponses.Revisions(e1.Local.Repository.GetTip().Number.Hash + ':' + e1.Local.Repository.GetTip().Branch);
                    e1.ApiServer.AddResponse(revisionResponse);
                    e1.LocalAddAndCommit();
                    e1.ApiServer.AddResponse(ApiResponses.PushComplete());
                    var tipHash1  = e1.Local.Repository.GetTip().Number.Hash;
                    var transport = provider.Transport;
                    transport.Push();
                    e1.ApiServer.AddResponse(ApiResponses.PushComplete());              // finishPushBundle

                    // push to ApiServer 2
                    api2.AddResponse(revisionResponse);
                    api2.AddResponse(ApiResponses.PushComplete());
                    transport2.Push();

                    // check contents of remoteRepoDb
                    string dbStoragePath = transport.PathToLocalStorage;
                    string dbFilePath    = Path.Combine(dbStoragePath, HgResumeTransport.RevisionCacheFilename);
                    var    cacheContents = HgResumeTransport.ReadServerRevisionCache(dbFilePath);
                    Assert.True(cacheContents.Count == 2, "should be two api server entries in the cache.");
                    Assert.True(cacheContents.SingleOrDefault(x => x.RemoteId == e1.ApiServer.Host).Revision.Number.Hash == tipHash1, "Cache contents incorrect");
                    Assert.True(cacheContents.SingleOrDefault(x => x.RemoteId == api2.Host).Revision.Number.Hash == tipHash1, "Cache contents incorrect");

                    // second push
                    e1.LocalAddAndCommit();
                    e1.LocalAddAndCommit();
                    string tipHash2 = e1.Local.Repository.GetTip().Number.Hash;
                    e1.ApiServer.AddResponse(ApiResponses.PushAccepted(1));
                    e1.ApiServer.AddResponse(ApiResponses.PushComplete());
                    transport.Push();

                    cacheContents = HgResumeTransport.ReadServerRevisionCache(dbFilePath);
                    Assert.True(cacheContents.Count == 2, "should be two api server entries in the cache.");
                    Assert.True(cacheContents.SingleOrDefault(x => x.RemoteId == e1.ApiServer.Host).Revision.Number.Hash == tipHash2, "Cache contents incorrect");
                    Assert.True(cacheContents.SingleOrDefault(x => x.RemoteId == api2.Host).Revision.Number.Hash == tipHash1, "Cache contents incorrect");

                    Assert.That(e1.Progress.AllMessages, Contains.Item("Finished sending"));
                }
        }
Esempio n. 2
0
        public TestEnvironment(string testName, ApiServerType type)
        {
            Local    = new RepositorySetup(testName + "-local");
            Remote   = new RepositorySetup(testName + "-remote");
            Progress = new ProgressForTest();
            switch (type)
            {
            case ApiServerType.Dummy:
                ApiServer = new DummyApiServerForTest(testName);
                break;

            case ApiServerType.Pull:
                ApiServer = new PullHandlerApiServerForTest(Remote.Repository, Progress);
                break;

            case ApiServerType.Push:
                ApiServer = new PushHandlerApiServerForTest(Remote.Repository, Progress);
                break;
            }
            Label         = testName;
            MultiProgress = new MultiProgress(new IProgress[] { new ConsoleProgress {
                                                                    ShowVerbose = true
                                                                }, Progress });
        }
Esempio n. 3
0
 public TestEnvironment(string testName, ApiServerType type)
 {
     Local = new RepositorySetup(testName + "-local");
     Remote = new RepositorySetup(testName + "-remote");
     Progress = new ProgressForTest();
     switch (type)
     {
         case ApiServerType.Dummy:
             ApiServer = new DummyApiServerForTest(testName);
             break;
         case ApiServerType.Pull:
             ApiServer = new PullHandlerApiServerForTest(Remote.Repository, Progress);
             break;
         case ApiServerType.Push:
             ApiServer = new PushHandlerApiServerForTest(Remote.Repository, Progress);
             break;
     }
     Label = testName;
     MultiProgress = new MultiProgress(new IProgress[] { new ConsoleProgress { ShowVerbose = true }, Progress });
 }
Esempio n. 4
0
        public void Push_2DifferentApiServers_HgRepoFileUpdatedWithBothEntries()
        {
            using (var e1 = new TestEnvironment("api1", ApiServerType.Dummy))
            using (var provider = GetTransportProviderForTest(e1))
            {
                var api2 = new DummyApiServerForTest("api3");
                var transport2 = new HgResumeTransport(e1.Local.Repository, "api3", api2, e1.MultiProgress);

                // push to ApiServer 1
                e1.LocalAddAndCommit();
                var revisionResponse = ApiResponses.Revisions(e1.Local.Repository.GetTip().Number.Hash + ':' + e1.Local.Repository.GetTip().Branch);
                e1.ApiServer.AddResponse(revisionResponse);
                e1.LocalAddAndCommit();
                e1.ApiServer.AddResponse(ApiResponses.PushComplete());
                var tipHash1 = e1.Local.Repository.GetTip().Number.Hash;
                var transport = provider.Transport;
                transport.Push();
                e1.ApiServer.AddResponse(ApiResponses.PushComplete());  // finishPushBundle

                // push to ApiServer 2
                api2.AddResponse(revisionResponse);
                api2.AddResponse(ApiResponses.PushComplete());
                transport2.Push();

                // check contents of remoteRepoDb
                string dbStoragePath = transport.PathToLocalStorage;
                string dbFilePath = Path.Combine(dbStoragePath, HgResumeTransport.RevisionCacheFilename);
                var cacheContents = HgResumeTransport.ReadServerRevisionCache(dbFilePath);
                Assert.True(cacheContents.Count == 2, "should be two api server entries in the cache.");
                Assert.True(cacheContents.SingleOrDefault(x => x.RemoteId == e1.ApiServer.Host).Revision.Number.Hash == tipHash1, "Cache contents incorrect");
                Assert.True(cacheContents.SingleOrDefault(x => x.RemoteId == api2.Host).Revision.Number.Hash == tipHash1, "Cache contents incorrect");

                // second push
                e1.LocalAddAndCommit();
                e1.LocalAddAndCommit();
                string tipHash2 = e1.Local.Repository.GetTip().Number.Hash;
                e1.ApiServer.AddResponse(ApiResponses.PushAccepted(1));
                e1.ApiServer.AddResponse(ApiResponses.PushComplete());
                transport.Push();

                cacheContents = HgResumeTransport.ReadServerRevisionCache(dbFilePath);
                Assert.True(cacheContents.Count == 2, "should be two api server entries in the cache.");
                Assert.True(cacheContents.SingleOrDefault(x => x.RemoteId == e1.ApiServer.Host).Revision.Number.Hash == tipHash2, "Cache contents incorrect");
                Assert.True(cacheContents.SingleOrDefault(x => x.RemoteId == api2.Host).Revision.Number.Hash == tipHash1, "Cache contents incorrect");

                Assert.That(e1.Progress.AllMessages, Contains.Item("Finished sending"));
            }
        }