예제 #1
0
        public void RemoteWorkerIsAbleToPerformNonBlockingMap()
        {
            var uri = new Uri("file:///ala.txt");
            var mapFunc = new Uri("file:///makota.cs");
            var mapLock = new object();
            var uriProviderMock = GetSimpleUriProvider();
            var storageMock = new Mock<IStorage>(MockBehavior.Strict);
            storageMock.Setup(s => s.GetFileName(It.IsAny<Uri>())).Returns(string.Empty);
            storageMock.Setup(s => s.Read(It.IsAny<Uri>())).Returns(string.Empty);
            var remoteWorkerServiceMock = new Mock<IRemoteWorkerService>(MockBehavior.Strict);
            remoteWorkerServiceMock.Setup(s => s.Init(It.IsAny<int>()));
            remoteWorkerServiceMock.Setup(s => s.Map(It.IsAny<Uri>(), It.IsAny<Uri>())).Callback(() =>
                {
                    lock (mapLock)
                    {
                        Monitor.Wait(mapLock);
                    }
                });

            remoteWorkerServiceMock.Setup(s => s.PushFile(It.IsAny<int>(), It.IsAny<string>(), It.IsAny<string>()))
                .Returns(new Uri("file:///a.txt"));
            MockerForRemoteWorkerService.Mock = remoteWorkerServiceMock.Object;
            RemoteWorker<MockerForRemoteWorkerService>.NonBlockingMapAndReduce = true;
            var worker = new RemoteWorker<MockerForRemoteWorkerService>()
            {
                Storage=storageMock.Object
            };
            worker.Init();

            worker.Map(uri, mapFunc);
            Thread.Sleep(10);
            lock (mapLock)
            {
                Monitor.Pulse(mapLock);
            }

            remoteWorkerServiceMock.VerifyAll();
        }
예제 #2
0
        public void RemoteWorkerWaitsForJoinInRemoteNode()
        {
            var joinLock = new object();
            var uriProviderMock = GetSimpleUriProvider();
            var remoteServiceMock = new Mock<IRemoteWorkerService>(MockBehavior.Strict);
            remoteServiceMock.Setup(s => s.Init(It.IsAny<int>()));
            remoteServiceMock.Setup(s => s.TryJoin(It.IsAny<int>(), It.IsAny<Uri>())).Returns(() =>
                {
                    lock (joinLock)
                    {
                        Monitor.Wait(joinLock);
                    }

                    return new string[] { "a" };
                });

            MockerForRemoteWorkerService.Mock = remoteServiceMock.Object;
            var worker = new RemoteWorker<MockerForRemoteWorkerService>();
            worker.Init();

            var joinThread = new Thread(() =>
            {
                worker.Join();
            });

            joinThread.Start();
            Thread.Sleep(10);

            joinThread.ThreadState.ShouldBe(ThreadState.WaitSleepJoin);
            lock (joinLock)
            {
                Monitor.Pulse(joinLock);
            }

            joinThread.Join();
            remoteServiceMock.VerifyAll();
        }
예제 #3
0
        public void RemoteReduceWorks()
        {
            var coordinatorStorage = new FileSystemStorage(@"c:\temp\netreduce\coordinator", true);

            var coordinatorProcess = Process.Start(new ProcessStartInfo(@"..\..\..\NetReduce.CoordinatorService.ConsoleHost\bin\Debug\NetReduce.CoordinatorService.ConsoleHost.exe"));
            Thread.Sleep(100);

            try
            {
                var workerStorage = new FileSystemStorage(@"c:\temp\netreduce\0", false);
                var reducerCodeFileName = new Uri("file:///SampleReducer.cs");
                TestHelpers.LoadToStorage(@"..\..\..\NetReduce.Core.Tests\SampleReducer.cs", reducerCodeFileName, this.storage);
                IUriProvider uriProvider = new UriProvider();
                uriProvider.Uris.Add(new Uri("http://*****:*****@"(?<Key>.+)", "[0-9]+", RegexExtensions.GuidRegexString));
                var uris = workerStorage.ListFiles();
                foreach (var uri in uris)
                {
                    var fileName = workerStorage.GetFileName(uri);
                    if (regex.IsMatch(fileName))
                    {
                        var key = regex.Match(fileName).Groups["Key"].Value;
                        if (Base64.Decode(key) == "k1")
                        {
                            result = workerStorage.Read(fileName);
                        }
                    }
                }

                result.ShouldBe("3");
            }
            finally
            {
                coordinatorProcess.Kill();
            }
        }
예제 #4
0
        public void RemoteMapWorks()
        {
            var fileName = new Uri(string.Format("file:///{0}", Base64.Encode("file1.txt")));
            var fileContent = "whatever am i i";
            var mapperCodeFileName = new Uri("file:///SampleMapper.cs");
            this.storage.Store(fileName, fileContent);
            TestHelpers.LoadToStorage(@"..\..\..\NetReduce.Core.Tests\SampleMapper.cs", mapperCodeFileName, this.storage);
            IUriProvider uriProvider = new UriProvider();
            uriProvider.Uris.Add(new Uri("http://*****:*****@"c:\temp\netreduce\0", false);
            var fileNo = workerStorage.ListFiles().Count();
            fileNo.ShouldBe(6);
        }