Exemple #1
0
        public void List()
        {
            // Arrange
            const string userId1          = "UserID1";
            const string userId2          = "UserID2";
            const string runspaceId       = "RunspaceId";
            const string sessionId        = "SessionId";
            var          sessionTokenMock = new Mock <ISessionToken>();

            sessionTokenMock.Setup(x => x.SessionId).Returns(sessionId);
            var runspaceProviderMockClass = new Mock <IRunspaceProvider>();
            var runspaceProviderMock      = MockRunspaceProvider(runspaceId, "127.0.0.1", runspaceProviderMockClass).Object;

            _multiTenantRunspaceProvider =
                new MultiTenantRunspaceProvider(
                    MockLoggerFactory(),
                    runspaceProviderMock);
            _multiTenantRunspaceProvider.StartCreate(userId1, sessionTokenMock.Object, null, false, null, null);
            _multiTenantRunspaceProvider.StartCreate(userId1, sessionTokenMock.Object, null, false, null, null);
            _multiTenantRunspaceProvider.StartCreate(userId2, sessionTokenMock.Object, null, false, null, null);

            // Act
            var actualUser1 = _multiTenantRunspaceProvider.List(userId1);
            var actualUser2 = _multiTenantRunspaceProvider.List(userId2);

            // Assert
            runspaceProviderMockClass.Verify(
                mock => mock.Get(
                    It.IsAny <string>()),
                Times.Exactly(3));
            Assert.AreEqual(2, actualUser1.Count());
            Assert.AreEqual(1, actualUser2.Count());
        }
Exemple #2
0
        public void ListWhenInvalidUser()
        {
            // Arrange
            const string invalidUserId    = "";
            const string userId           = "UserId";
            const string runspaceId       = "RunspaceId";
            const string sessionId        = "SessionId";
            var          sessionTokenMock = new Mock <ISessionToken>();

            sessionTokenMock.Setup(x => x.SessionId).Returns(sessionId);
            var runspaceProviderMockClass = new Mock <IRunspaceProvider>();
            var runspaceProviderMock      = MockRunspaceProvider(runspaceId, "127.0.0.1", runspaceProviderMockClass).Object;

            _multiTenantRunspaceProvider =
                new MultiTenantRunspaceProvider(
                    MockLoggerFactory(),
                    runspaceProviderMock);
            _multiTenantRunspaceProvider.StartCreate(userId, sessionTokenMock.Object, null, false, null, null);

            // Act && Assert
            Assert.Throws <RunspaceProviderException>(
                () => _multiTenantRunspaceProvider.List(invalidUserId));
        }
Exemple #3
0
        public void CleanupRemovesLocalDataForDisappearedRunspaces()
        {
            // Arrange
            const string userId           = "UserID";
            const string sessionId        = "session-id-1";
            const string runspaceId1      = "runspace-id-1";
            const string runspaceId2      = "runspace-id-2";
            var          sessionTokenMock = new Mock <ISessionToken>();

            sessionTokenMock.Setup(x => x.SessionId).Returns(sessionId);

            // Mock Runspaces Info
            var runspace1 = new Mock <IRunspaceInfo>();

            runspace1.Setup(r => r.Id).Returns(runspaceId1);

            var runspace2 = new Mock <IRunspaceInfo>();

            runspace2.Setup(r => r.Id).Returns(runspaceId2);

            // Mock RunspaceProvider
            var rsProvider = new Mock <IRunspaceProvider>();

            rsProvider.Setup(p => p.Kill(It.IsAny <string>()));
            int callCount = 0;

            rsProvider.Setup(p => p.StartCreate()).Returns(
                () => {
                if (callCount == 0)
                {
                    callCount = 1;
                    return(runspace1.Object);
                }
                else
                {
                    return(runspace2.Object);
                }
            });
            rsProvider.Setup(p => p.List()).Returns(new[] { runspace1.Object });
            rsProvider.Setup(p => p.Get(runspaceId1)).Returns(runspace1.Object);
            rsProvider.Setup(p => p.Get(runspaceId2)).Returns(runspace2.Object);

            // Mock RunsapcesStatsMonitor
            var runspacesStatsMonitor = new Mock <IRunspacesStatsMonitor>();

            runspacesStatsMonitor.Setup(m => m.EvaluateRunspacesToRemove()).Returns(new string[] {});

            runspacesStatsMonitor.Setup(m => m.GetRegisteredRunspaces()).Returns(new [] { runspaceId1, runspaceId2 });
            runspacesStatsMonitor.Setup(m => m.Unregister(runspaceId2));

            _multiTenantRunspaceProvider =
                new MultiTenantRunspaceProvider(
                    MockLoggerFactory(),
                    rsProvider.Object,
                    Int32.MaxValue,
                    Int32.MaxValue,
                    Int32.MaxValue,
                    runspacesStatsMonitor.Object);

            _multiTenantRunspaceProvider.StartCreate(userId, sessionTokenMock.Object, null, false, null, null);
            _multiTenantRunspaceProvider.StartCreate(userId, sessionTokenMock.Object, null, false, null, null);

            // Act
            _multiTenantRunspaceProvider.Cleanup();

            // Assert
            // Stats Monitor Unregister is called
            runspacesStatsMonitor.Verify(mock => mock.Unregister(runspaceId2), Times.AtLeastOnce);

            // Only Runspace2 is left
            var userRunspaces = _multiTenantRunspaceProvider.List(userId);

            Assert.AreEqual(1, userRunspaces.Count());
            Assert.AreEqual(runspaceId1, userRunspaces.First().Id);
        }