Search in sources :

Example 1 with ServerResponsibility

use of jetbrains.buildServer.serverSide.ServerResponsibility in project teamcity-torrent-plugin by JetBrains.

the class TorrentTrackerManagerTest method setUp.

@BeforeMethod
public void setUp() throws Exception {
    Mockery m = new Mockery();
    final XmlRpcHandlerManager rpcHandlerManager = m.mock(XmlRpcHandlerManager.class);
    final ExecutorServices executorServices = m.mock(ExecutorServices.class);
    final ServerResponsibility serverResponsibility = m.mock(ServerResponsibility.class);
    myExecutorService = Executors.newScheduledThreadPool(4);
    final RootUrlHolder rootUrlHolder = m.mock(RootUrlHolder.class);
    m.checking(new Expectations() {

        {
            allowing(rpcHandlerManager).addHandler(with(any(String.class)), with(any(Object.class)));
            allowing(executorServices).getNormalExecutorService();
            will(returnValue(myExecutorService));
            allowing(rootUrlHolder).getRootUrl();
            will(returnValue("http://localhost:8111"));
            allowing(serverResponsibility).canManageServerConfig();
            will(returnValue(true));
        }
    });
    myTorrentTrackerManager = new TorrentTrackerManager(new TorrentConfigurator(new ServerPaths(createTempDir().getAbsolutePath()), rootUrlHolder, rpcHandlerManager), executorServices, new EventDispatcher<BuildServerListener>(BuildServerListener.class) {
    }, m.mock(AddressChecker.class), serverResponsibility);
}
Also used : XmlRpcHandlerManager(jetbrains.buildServer.XmlRpcHandlerManager) Expectations(org.jmock.Expectations) RootUrlHolder(jetbrains.buildServer.RootUrlHolder) EventDispatcher(jetbrains.buildServer.util.EventDispatcher) ExecutorServices(jetbrains.buildServer.serverSide.executors.ExecutorServices) ServerResponsibility(jetbrains.buildServer.serverSide.ServerResponsibility) Mockery(org.jmock.Mockery) ServerPaths(jetbrains.buildServer.serverSide.ServerPaths) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 2 with ServerResponsibility

use of jetbrains.buildServer.serverSide.ServerResponsibility in project teamcity-torrent-plugin by JetBrains.

the class TorrentTrackerConfiguratorTest method setUp.

@BeforeMethod
@Override
protected void setUp() throws Exception {
    super.setUp();
    Mockery m = new Mockery();
    final AddressChecker addressChecker = m.mock(AddressChecker.class);
    final ServerResponsibility serverResponsibility = m.mock(ServerResponsibility.class);
    m.checking(new Expectations() {

        {
            allowing(addressChecker).isBadAddress(with(any(String.class)));
            will(returnValue(false));
            allowing(serverResponsibility).canManageServerConfig();
            will(returnValue(true));
        }
    });
    myTrackerManager = new TorrentTrackerManager(myConfigurator, new ExecutorServices() {

        @NotNull
        public ScheduledExecutorService getNormalExecutorService() {
            return ExecutorsFactory.newFixedScheduledExecutor("aaa", 1);
        }

        @NotNull
        public ExecutorService getLowPriorityExecutorService() {
            return null;
        }
    }, myDispatcher, addressChecker, serverResponsibility);
    myDispatcher.getMulticaster().serverStartup();
    new WaitFor(5 * 1000) {

        @Override
        protected boolean condition() {
            return !myTorrentsSeeder.getTorrentsSeeder().isStopped();
        }
    };
    assertFalse(myTorrentsSeeder.getTorrentsSeeder().isStopped());
}
Also used : Expectations(org.jmock.Expectations) AddressChecker(com.turn.ttorrent.tracker.AddressChecker) WaitFor(jetbrains.buildServer.util.WaitFor) ExecutorServices(jetbrains.buildServer.serverSide.executors.ExecutorServices) ServerResponsibility(jetbrains.buildServer.serverSide.ServerResponsibility) Mockery(org.jmock.Mockery) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 3 with ServerResponsibility

use of jetbrains.buildServer.serverSide.ServerResponsibility in project teamcity-git by JetBrains.

the class GitHubPasswordAuthRootRegistryImplTest method test.

@Test
public void test() {
    final Map<String, Long> events = new HashMap<>();
    final MockTimeService timeService = new MockTimeService();
    final Map<String, String> vcsProperties = CollectionsUtil.asMap(VcsUtil.VCS_NAME_PROP, Constants.VCS_NAME, Constants.AUTH_METHOD, AuthenticationMethod.PASSWORD.name(), Constants.FETCH_URL, "https://github.com/name/repo.git", Constants.PASSWORD, "%some.param%");
    final Mockery mockery = new Mockery();
    final ProjectManager projectManager = mockery.mock(ProjectManager.class);
    final ServerResponsibility serverResponsibility = mockery.mock(ServerResponsibility.class);
    mockery.checking(new Expectations() {

        {
            allowing(projectManager).findVcsRootById(1);
            final MockSVcsRoot vcsRoot = new MockSVcsRoot(1, Constants.VCS_NAME);
            vcsRoot.setProperties(vcsProperties);
            will(returnValue(vcsRoot));
            allowing(serverResponsibility).canCheckForChanges();
            will(returnValue(true));
        }
    });
    final GitHubPasswordAuthRootRegistryImpl registry = new GitHubPasswordAuthRootRegistryImpl(new EventDispatcher<BuildServerListener>(BuildServerListener.class) {
    }, new EventDispatcher<RepositoryStateListener>(RepositoryStateListener.class) {
    }, projectManager, serverResponsibility, createMultiNodesEvents(events), timeService);
    vcsProperties.put(Constants.PASSWORD, "12345");
    registry.update(new VcsRootImpl(1, vcsProperties));
    assertTrue(registry.containsVcsRoot(1));
    BaseTestCase.assertMap(registry.getRegistry(), 1L, timeService.myTime);
    BaseTestCase.assertMap(events, "gitHubPasswordAuthUsageAdd", 1L);
    events.clear();
    timeService.inc();
    registry.update(new VcsRootImpl(1, vcsProperties));
    assertTrue(registry.containsVcsRoot(1));
    BaseTestCase.assertMap(registry.getRegistry(), 1L, timeService.myTime);
    assertTrue(events.isEmpty());
    timeService.inc();
    final VcsRootInstanceContext context = mockery.mock(VcsRootInstanceContext.class);
    mockery.checking(new Expectations() {

        {
            allowing(context).getTimeService();
            will(returnValue(timeService));
            allowing(context).getServerMetrics();
            will(returnValue(null));
        }
    });
    registry.update(new VcsRootInstanceImpl(100, Constants.VCS_NAME, 1, "My Name", vcsProperties, context));
    assertTrue(registry.containsVcsRoot(1));
    BaseTestCase.assertMap(registry.getRegistry(), 1L, timeService.myTime);
    assertTrue(events.isEmpty());
    timeService.inc();
    vcsProperties.put(Constants.PASSWORD, "1234567890abcdef1234567890abcdef12345678");
    registry.update(new VcsRootImpl(1, vcsProperties));
    assertTrue(registry.containsVcsRoot(1));
    BaseTestCase.assertMap(registry.getRegistry(), 1L, timeService.myTime - 1);
    assertTrue(events.isEmpty());
    setInternalProperty("teamcity.git.gitHubPasswordAuthHealthReport.updateIntervalSec", "300");
    timeService.inc(350, TimeUnit.SECONDS);
    registry.update(new VcsRootImpl(1, vcsProperties));
    assertFalse(registry.containsVcsRoot(1));
    assertTrue(registry.getRegistry().isEmpty());
    BaseTestCase.assertMap(events, "gitHubPasswordAuthUsageRemove", 1L);
    events.clear();
    timeService.inc();
    vcsProperties.put(Constants.PASSWORD, "12345");
    registry.update(new VcsRootImpl(1, vcsProperties));
    assertTrue(registry.containsVcsRoot(1));
    BaseTestCase.assertMap(registry.getRegistry(), 1L, timeService.myTime);
    BaseTestCase.assertMap(events, "gitHubPasswordAuthUsageAdd", 1L);
    events.clear();
    timeService.inc();
    // see TW-71026
    vcsProperties.put(Constants.PASSWORD, "gho_oPan0zUSMxvI7NoWDBjjBP965641HX2NHNbu");
    timeService.inc(350, TimeUnit.SECONDS);
    registry.update(new VcsRootImpl(1, vcsProperties));
    assertFalse(registry.containsVcsRoot(1));
    assertTrue(registry.getRegistry().isEmpty());
    BaseTestCase.assertMap(events, "gitHubPasswordAuthUsageRemove", 1L);
    {
        // add root to registry again
        events.clear();
        timeService.inc();
        vcsProperties.put(Constants.PASSWORD, "12345");
        registry.update(new VcsRootImpl(1, vcsProperties));
        assertTrue(registry.containsVcsRoot(1));
        BaseTestCase.assertMap(registry.getRegistry(), 1L, timeService.myTime);
        BaseTestCase.assertMap(events, "gitHubPasswordAuthUsageAdd", 1L);
    }
    {
        // TW-72780
        events.clear();
        timeService.inc();
        vcsProperties.put(Constants.AUTH_METHOD, AuthenticationMethod.ANONYMOUS.name());
        timeService.inc(350, TimeUnit.SECONDS);
        registry.update(new VcsRootImpl(1, vcsProperties));
        assertFalse(registry.containsVcsRoot(1));
        assertTrue(registry.getRegistry().isEmpty());
        BaseTestCase.assertMap(events, "gitHubPasswordAuthUsageRemove", 1L);
    }
    {
        // TW-73295
        events.clear();
        timeService.inc();
        timeService.inc(350, TimeUnit.SECONDS);
        registry.update(new VcsRootImpl(1, vcsProperties));
        assertFalse(registry.containsVcsRoot(1));
        assertTrue(registry.getRegistry().isEmpty());
        assertTrue(events.isEmpty());
    }
}
Also used : Expectations(org.jmock.Expectations) MockSVcsRoot(jetbrains.buildServer.vcs.MockSVcsRoot) HashMap(java.util.HashMap) RepositoryStateListener(jetbrains.buildServer.vcs.RepositoryStateListener) ServerResponsibility(jetbrains.buildServer.serverSide.ServerResponsibility) MockTimeService(jetbrains.buildServer.MockTimeService) BuildServerListener(jetbrains.buildServer.serverSide.BuildServerListener) Mockery(org.jmock.Mockery) GitHubPasswordAuthRootRegistryImpl(jetbrains.buildServer.buildTriggers.vcs.git.GitHubPasswordAuthRootRegistryImpl) ProjectManager(jetbrains.buildServer.serverSide.ProjectManager) VcsRootImpl(jetbrains.buildServer.vcs.impl.VcsRootImpl) VcsRootInstanceImpl(jetbrains.buildServer.vcs.impl.VcsRootInstanceImpl) VcsRootInstanceContext(jetbrains.buildServer.serverSide.impl.beans.VcsRootInstanceContext) Test(org.testng.annotations.Test)

Example 4 with ServerResponsibility

use of jetbrains.buildServer.serverSide.ServerResponsibility in project teamcity-torrent-plugin by JetBrains.

the class ServerTorrentsSeederTestCase method setUp.

@BeforeMethod
@Override
protected void setUp() throws Exception {
    super.setUp();
    final Mockery m = new Mockery();
    final ServerPaths serverPaths = new ServerPaths(createTempDir().getAbsolutePath());
    final RootUrlHolder rootUrlHolder = m.mock(RootUrlHolder.class);
    final ExecutorServices executorServices = m.mock(ExecutorServices.class);
    myExecutorService = Executors.newScheduledThreadPool(1);
    final ServerResponsibility serverResponsibility = m.mock(ServerResponsibility.class);
    m.checking(new Expectations() {

        {
            allowing(rootUrlHolder).getRootUrl();
            will(returnValue("http://localhost:8111/"));
            allowing(executorServices).getNormalExecutorService();
            will(returnValue(myExecutorService));
            allowing(serverResponsibility).canManageBuilds();
            will(returnValue(true));
        }
    });
    final ServerSettings serverSettings = m.mock(ServerSettings.class);
    m.checking(new Expectations() {

        {
            allowing(serverSettings).getArtifactDirectories();
            will(returnValue(Collections.singletonList(serverPaths.getArtifactsDirectory())));
        }
    });
    myConfigurator = new TorrentConfigurator(serverPaths, rootUrlHolder, new XmlRpcHandlerManager() {

        public void addHandler(String handlerName, Object handler) {
        }

        public void addSessionHandler(String handlerName, Object handler) {
        }
    });
    myConfigurator.setDownloadEnabled(true);
    myConfigurator.setSeedingEnabled(true);
    myDispatcher = EventDispatcher.create(BuildServerListener.class);
    myTorrentsSeeder = new ServerTorrentsDirectorySeeder(serverPaths, serverSettings, myConfigurator, myDispatcher, executorServices, new SelectorFactoryImpl(), new TrackerClientFactoryImpl(), serverResponsibility);
}
Also used : Expectations(org.jmock.Expectations) SelectorFactoryImpl(com.turn.ttorrent.client.SelectorFactoryImpl) RootUrlHolder(jetbrains.buildServer.RootUrlHolder) ServerResponsibility(jetbrains.buildServer.serverSide.ServerResponsibility) TrackerClientFactoryImpl(com.turn.ttorrent.client.announce.TrackerClientFactoryImpl) BuildServerListener(jetbrains.buildServer.serverSide.BuildServerListener) Mockery(org.jmock.Mockery) XmlRpcHandlerManager(jetbrains.buildServer.XmlRpcHandlerManager) ServerSettings(jetbrains.buildServer.serverSide.ServerSettings) ExecutorServices(jetbrains.buildServer.serverSide.executors.ExecutorServices) ServerPaths(jetbrains.buildServer.serverSide.ServerPaths) BeforeMethod(org.testng.annotations.BeforeMethod)

Aggregations

ServerResponsibility (jetbrains.buildServer.serverSide.ServerResponsibility)4 Expectations (org.jmock.Expectations)4 Mockery (org.jmock.Mockery)4 ExecutorServices (jetbrains.buildServer.serverSide.executors.ExecutorServices)3 BeforeMethod (org.testng.annotations.BeforeMethod)3 RootUrlHolder (jetbrains.buildServer.RootUrlHolder)2 XmlRpcHandlerManager (jetbrains.buildServer.XmlRpcHandlerManager)2 BuildServerListener (jetbrains.buildServer.serverSide.BuildServerListener)2 ServerPaths (jetbrains.buildServer.serverSide.ServerPaths)2 SelectorFactoryImpl (com.turn.ttorrent.client.SelectorFactoryImpl)1 TrackerClientFactoryImpl (com.turn.ttorrent.client.announce.TrackerClientFactoryImpl)1 AddressChecker (com.turn.ttorrent.tracker.AddressChecker)1 HashMap (java.util.HashMap)1 MockTimeService (jetbrains.buildServer.MockTimeService)1 GitHubPasswordAuthRootRegistryImpl (jetbrains.buildServer.buildTriggers.vcs.git.GitHubPasswordAuthRootRegistryImpl)1 ProjectManager (jetbrains.buildServer.serverSide.ProjectManager)1 ServerSettings (jetbrains.buildServer.serverSide.ServerSettings)1 VcsRootInstanceContext (jetbrains.buildServer.serverSide.impl.beans.VcsRootInstanceContext)1 EventDispatcher (jetbrains.buildServer.util.EventDispatcher)1 WaitFor (jetbrains.buildServer.util.WaitFor)1