Search in sources :

Example 1 with SystemConfig

use of org.jboss.pnc.common.json.moduleconfig.SystemConfig in project pnc by project-ncl.

the class MessageSenderProviderTest method shouldGetMessageSender.

@Test
public void shouldGetMessageSender() throws MessagingConfigurationException {
    // given
    Instance<MessageSender> messageSenders = getMessageSenders();
    SystemConfig systemConfig = Mockito.mock(SystemConfig.class);
    Mockito.when(systemConfig.getMessageSenderId()).thenReturn(MessageSender2.class.getName());
    // when
    MessageSenderProvider messageSenderProvider = new MessageSenderProvider(messageSenders, systemConfig);
    // expect
    Optional<MessageSender> selectedMessageSender = messageSenderProvider.getMessageSender();
    Assert.assertTrue(selectedMessageSender.isPresent());
    Assert.assertEquals(MessageSender2.class.getName(), selectedMessageSender.get().getMessageSenderId());
    Assert.assertTrue(((AbstractMessageSender) selectedMessageSender.get()).initialized);
}
Also used : SystemConfig(org.jboss.pnc.common.json.moduleconfig.SystemConfig) MessageSender(org.jboss.pnc.messaging.spi.MessageSender) Test(org.junit.Test)

Example 2 with SystemConfig

use of org.jboss.pnc.common.json.moduleconfig.SystemConfig in project pnc by project-ncl.

the class AbstractDependentBuildTest method initialize.

@Before
@SuppressWarnings("unchecked")
public void initialize() throws DatastoreException, ConfigurationParseException {
    MockitoAnnotations.initMocks(this);
    builtTasks = new ArrayList<>();
    user = new User();
    user.setId(375939);
    user.setUsername("username");
    Configuration config = mock(Configuration.class);
    SystemConfig systemConfig = mock(SystemConfig.class);
    when(systemConfig.getCoordinatorThreadPoolSize()).thenReturn(1);
    when(systemConfig.getCoordinatorMaxConcurrentBuilds()).thenReturn(1);
    when(systemConfig.getTemporaryBuildsLifeSpan()).thenReturn(1);
    when(config.getModuleConfig(any())).thenReturn(systemConfig);
    buildQueue = new BuildQueue(config.getModuleConfig(new PncConfigProvider<>(SystemConfig.class)));
    if (buildConfigurationRepository == null) {
        buildConfigurationRepository = new BuildConfigurationRepositoryMock();
    }
    buildRecordRepository = new BuildRecordRepositoryMock();
    buildConfigurationAuditedRepository = new BuildConfigurationAuditedRepositoryMock();
    TargetRepositoryRepository targetRepositoryRepository = new TargetRepositoryRepositoryMock();
    DefaultDatastore datastore = new DefaultDatastore(new ArtifactRepositoryMock(), buildRecordRepository, buildConfigurationRepository, buildConfigurationAuditedRepository, new BuildConfigSetRecordRepositoryMock(), new UserRepositoryMock(), targetRepositoryRepository);
    DatastoreAdapter datastoreAdapter = new DatastoreAdapter(datastore);
    if (buildSchedulerFactory == null) {
        buildSchedulerFactory = new MockBuildSchedulerFactory();
    }
    coordinator = new DefaultBuildCoordinator(datastoreAdapter, mock(Event.class), mock(Event.class), buildSchedulerFactory, buildQueue, systemConfig, mock(GroupBuildMapper.class), mock(BuildMapper.class));
    buildQueue.initSemaphore();
    coordinator.start();
}
Also used : BuildQueue(org.jboss.pnc.coordinator.builder.BuildQueue) SystemConfig(org.jboss.pnc.common.json.moduleconfig.SystemConfig) User(org.jboss.pnc.model.User) BuildConfigSetRecordRepositoryMock(org.jboss.pnc.mock.repository.BuildConfigSetRecordRepositoryMock) BuildConfiguration(org.jboss.pnc.model.BuildConfiguration) BuildExecutionConfiguration(org.jboss.pnc.spi.executor.BuildExecutionConfiguration) RepositoryConfiguration(org.jboss.pnc.model.RepositoryConfiguration) Configuration(org.jboss.pnc.common.Configuration) BuildRecordRepositoryMock(org.jboss.pnc.mock.repository.BuildRecordRepositoryMock) TargetRepositoryRepositoryMock(org.jboss.pnc.mock.repository.TargetRepositoryRepositoryMock) BuildConfigurationRepositoryMock(org.jboss.pnc.mock.repository.BuildConfigurationRepositoryMock) BuildConfigurationAuditedRepositoryMock(org.jboss.pnc.mock.repository.BuildConfigurationAuditedRepositoryMock) TargetRepositoryRepository(org.jboss.pnc.spi.datastore.repositories.TargetRepositoryRepository) DatastoreAdapter(org.jboss.pnc.coordinator.builder.datastore.DatastoreAdapter) DefaultBuildCoordinator(org.jboss.pnc.coordinator.builder.DefaultBuildCoordinator) DefaultDatastore(org.jboss.pnc.datastore.DefaultDatastore) ArtifactRepositoryMock(org.jboss.pnc.mock.repository.ArtifactRepositoryMock) UserRepositoryMock(org.jboss.pnc.mock.repository.UserRepositoryMock) Before(org.junit.Before)

Example 3 with SystemConfig

use of org.jboss.pnc.common.json.moduleconfig.SystemConfig in project pnc by project-ncl.

the class LivenessProbeTest method shouldFailTheBuildWhenAgentIsNotResponding.

@Test
public void shouldFailTheBuildWhenAgentIsNotResponding() throws InterruptedException, BuildDriverException {
    TermdBuildDriverModuleConfig buildDriverModuleConfig = mock(TermdBuildDriverModuleConfig.class);
    doReturn(200L).when(buildDriverModuleConfig).getLivenessProbeFrequencyMillis();
    doReturn(500L).when(buildDriverModuleConfig).getLivenessFailTimeoutMillis();
    ClientMockFactory buildAgentClientMockFactory = new ClientMockFactory();
    TermdBuildDriver driver = new TermdBuildDriver(systemConfig, buildDriverModuleConfig, buildAgentClientMockFactory);
    BuildExecutionSession buildExecution = mock(BuildExecutionSession.class);
    BuildExecutionConfiguration buildExecutionConfiguration = mock(BuildExecutionConfiguration.class);
    doReturn(buildExecutionConfiguration).when(buildExecution).getBuildExecutionConfiguration();
    RunningEnvironment runningEnvironment = mock(RunningEnvironment.class);
    doReturn(Paths.get("")).when(runningEnvironment).getWorkingDirectory();
    doReturn(new DebugData(false)).when(runningEnvironment).getDebugData();
    doReturn("http://localhost/").when(runningEnvironment).getInternalBuildAgentUrl();
    doReturn(runningEnvironment).when(buildExecution).getRunningEnvironment();
    BlockingQueue<Throwable> result = new ArrayBlockingQueue(1);
    Consumer<CompletedBuild> onComplete = (completedBuild) -> Assert.fail("Build should complete with error.");
    Consumer<Throwable> onError = (throwable) -> {
        try {
            result.put(throwable);
        } catch (InterruptedException e) {
            Assert.fail("Error in the test. Unable to add the result to queue.");
        }
    };
    // when
    RunningBuild runningBuild = driver.startProjectBuild(buildExecution, runningEnvironment, onComplete, onError);
    // then
    Throwable throwable = result.poll(1, TimeUnit.SECONDS);
    Assert.assertNotNull("It should complete with an exception.", throwable);
    Assert.assertEquals("Build Agent has gone away.", throwable.getMessage());
}
Also used : BuildExecutionSession(org.jboss.pnc.spi.executor.BuildExecutionSession) CompletedBuild(org.jboss.pnc.spi.builddriver.CompletedBuild) Logger(org.slf4j.Logger) BuildDriverException(org.jboss.pnc.spi.builddriver.exception.BuildDriverException) RunningBuild(org.jboss.pnc.spi.builddriver.RunningBuild) LoggerFactory(org.slf4j.LoggerFactory) CompletedBuild(org.jboss.pnc.spi.builddriver.CompletedBuild) Test(org.junit.Test) BlockingQueue(java.util.concurrent.BlockingQueue) TimeUnit(java.util.concurrent.TimeUnit) Consumer(java.util.function.Consumer) ArrayBlockingQueue(java.util.concurrent.ArrayBlockingQueue) RunningEnvironment(org.jboss.pnc.spi.environment.RunningEnvironment) Paths(java.nio.file.Paths) DebugData(org.jboss.pnc.spi.builddriver.DebugData) TermdBuildDriverModuleConfig(org.jboss.pnc.common.json.moduleconfig.TermdBuildDriverModuleConfig) BuildExecutionConfiguration(org.jboss.pnc.spi.executor.BuildExecutionConfiguration) SystemConfig(org.jboss.pnc.common.json.moduleconfig.SystemConfig) Assert(org.junit.Assert) BuildExecutionSession(org.jboss.pnc.spi.executor.BuildExecutionSession) Mockito.doReturn(org.mockito.Mockito.doReturn) Mockito.mock(org.mockito.Mockito.mock) BuildExecutionConfiguration(org.jboss.pnc.spi.executor.BuildExecutionConfiguration) DebugData(org.jboss.pnc.spi.builddriver.DebugData) RunningBuild(org.jboss.pnc.spi.builddriver.RunningBuild) RunningEnvironment(org.jboss.pnc.spi.environment.RunningEnvironment) TermdBuildDriverModuleConfig(org.jboss.pnc.common.json.moduleconfig.TermdBuildDriverModuleConfig) ArrayBlockingQueue(java.util.concurrent.ArrayBlockingQueue) Test(org.junit.Test)

Example 4 with SystemConfig

use of org.jboss.pnc.common.json.moduleconfig.SystemConfig in project pnc by project-ncl.

the class TermdBuildDriverTest method shouldStartAndCancelTheExecutionImmediately.

@Test(timeout = 5_000)
public void shouldStartAndCancelTheExecutionImmediately() throws ConfigurationParseException, BuildDriverException, InterruptedException, IOException {
    // given
    String dirName = "test-workdir";
    String logStart = "Running the command...";
    String logEnd = "Command completed.";
    TermdBuildDriver driver = new TermdBuildDriver(systemConfig, buildDriverModuleConfig, clientFactory);
    BuildExecutionSession buildExecution = mock(BuildExecutionSession.class);
    BuildExecutionConfiguration buildExecutionConfiguration = mock(BuildExecutionConfiguration.class);
    doReturn("echo \"" + logStart + "\"; mvn validate; echo \"" + logEnd + "\";").when(buildExecutionConfiguration).getBuildScript();
    doReturn(dirName).when(buildExecutionConfiguration).getName();
    doReturn(buildExecutionConfiguration).when(buildExecution).getBuildExecutionConfiguration();
    AtomicReference<CompletedBuild> buildResult = new AtomicReference<>();
    // when
    CountDownLatch latch = new CountDownLatch(1);
    Consumer<CompletedBuild> onComplete = (completedBuild) -> {
        buildResult.set(completedBuild);
        latch.countDown();
    };
    Consumer<Throwable> onError = (throwable) -> {
        logger.error("Error received: ", throwable);
        fail(throwable.getMessage());
    };
    RunningBuild runningBuild = driver.startProjectBuild(buildExecution, localEnvironmentPointer, onComplete, onError);
    runningBuild.cancel();
    latch.await();
    // then
    assertThat(buildResult.get().getBuildResult().getBuildLog()).doesNotContain(logEnd);
    assertThat(buildResult.get().getBuildResult().getBuildStatus()).isEqualTo(CANCELLED);
}
Also used : BuildExecutionSession(org.jboss.pnc.spi.executor.BuildExecutionSession) CompletedBuild(org.jboss.pnc.spi.builddriver.CompletedBuild) CANCELLED(org.jboss.pnc.enums.BuildStatus.CANCELLED) BuildDriverException(org.jboss.pnc.spi.builddriver.exception.BuildDriverException) RunningBuild(org.jboss.pnc.spi.builddriver.RunningBuild) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) LoggerFactory(org.slf4j.LoggerFactory) AtomicReference(java.util.concurrent.atomic.AtomicReference) ConfigurationParseException(org.jboss.pnc.common.json.ConfigurationParseException) Assert.fail(org.junit.Assert.fail) BuildExecutionConfiguration(org.jboss.pnc.spi.executor.BuildExecutionConfiguration) Path(java.nio.file.Path) Mockito.doReturn(org.mockito.Mockito.doReturn) Logger(org.slf4j.Logger) TaskStatusUpdateEvent(org.jboss.pnc.buildagent.api.TaskStatusUpdateEvent) Files(java.nio.file.Files) MethodHandles(java.lang.invoke.MethodHandles) CompletedBuild(org.jboss.pnc.spi.builddriver.CompletedBuild) Test(org.junit.Test) IOException(java.io.IOException) Consumer(java.util.function.Consumer) CountDownLatch(java.util.concurrent.CountDownLatch) RunningEnvironment(org.jboss.pnc.spi.environment.RunningEnvironment) Status(org.jboss.pnc.buildagent.api.Status) SystemConfig(org.jboss.pnc.common.json.moduleconfig.SystemConfig) BuildExecutionSession(org.jboss.pnc.spi.executor.BuildExecutionSession) Mockito.mock(org.mockito.Mockito.mock) BuildExecutionConfiguration(org.jboss.pnc.spi.executor.BuildExecutionConfiguration) RunningBuild(org.jboss.pnc.spi.builddriver.RunningBuild) AtomicReference(java.util.concurrent.atomic.AtomicReference) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.Test)

Example 5 with SystemConfig

use of org.jboss.pnc.common.json.moduleconfig.SystemConfig in project pnc by project-ncl.

the class CancelledBuildByBpmTest method buildSingleProjectTestCase.

@Test(timeout = 5_000)
public void buildSingleProjectTestCase() throws Exception {
    // given
    DatastoreMock datastoreMock = new DatastoreMock();
    TestProjectConfigurationBuilder configurationBuilder = new TestProjectConfigurationBuilder(datastoreMock);
    DatastoreAdapter datastoreAdapter = new DatastoreAdapter(datastoreMock);
    SystemConfig systemConfig = createConfiguration();
    BuildQueue queue = new BuildQueue(systemConfig);
    BlockingQueue<BuildStatusChangedEvent> receivedStatuses = new ArrayBlockingQueue<>(5);
    Consumer<BuildStatusChangedEvent> onStatusUpdate = receivedStatuses::add;
    EventListener buildStatusChangedEventNotifier = new EventListener(onStatusUpdate);
    BlockingQueue<BpmTask> task = new ArrayBlockingQueue<>(5);
    Consumer<BpmTask> onBpmTaskCreated = task::add;
    BuildSchedulerFactory buildSchedulerFactory = new BuildSchedulerFactory(onBpmTaskCreated);
    BuildCoordinator coordinator = new DefaultBuildCoordinator(datastoreAdapter, buildStatusChangedEventNotifier, null, buildSchedulerFactory, queue, systemConfig, groupBuildMapper, buildMapper);
    coordinator.start();
    queue.initSemaphore();
    coordinator.build(configurationBuilder.buildConfigurationToCancel(1, "c1-bpm"), MockUser.newTestUser(1), new BuildOptions());
    waitForStatus(receivedStatuses, BuildStatus.BUILDING);
    BpmTask bpmTask = task.poll(1, TimeUnit.SECONDS);
    BuildResultRest result = new BuildResultRest();
    result.setCompletionStatus(CompletionStatus.CANCELLED);
    // when
    bpmTask.notify(BUILD_COMPLETE, result);
    waitForStatus(receivedStatuses, BuildStatus.CANCELLED);
    // expect
    List<BuildRecord> buildRecords = datastoreMock.getBuildRecords();
    Assert.assertEquals("Too many build records in datastore: " + buildRecords, 1, buildRecords.size());
    BuildRecord buildRecord = buildRecords.get(0);
    Assert.assertNotNull(buildRecord.getSubmitTime());
    Assert.assertNotNull(buildRecord.getStartTime());
    Assert.assertNotNull(buildRecord.getEndTime());
    Assert.assertEquals(BuildStatus.CANCELLED, buildRecord.getStatus());
}
Also used : BuildQueue(org.jboss.pnc.coordinator.builder.BuildQueue) BuildCoordinator(org.jboss.pnc.spi.coordinator.BuildCoordinator) DefaultBuildCoordinator(org.jboss.pnc.coordinator.builder.DefaultBuildCoordinator) SystemConfig(org.jboss.pnc.common.json.moduleconfig.SystemConfig) BpmTask(org.jboss.pnc.bpm.BpmTask) TestProjectConfigurationBuilder(org.jboss.pnc.mock.model.builders.TestProjectConfigurationBuilder) BuildStatusChangedEvent(org.jboss.pnc.spi.events.BuildStatusChangedEvent) DatastoreMock(org.jboss.pnc.mock.datastore.DatastoreMock) BuildRecord(org.jboss.pnc.model.BuildRecord) BuildResultRest(org.jboss.pnc.bpm.model.BuildResultRest) ArrayBlockingQueue(java.util.concurrent.ArrayBlockingQueue) BuildOptions(org.jboss.pnc.spi.BuildOptions) DatastoreAdapter(org.jboss.pnc.coordinator.builder.datastore.DatastoreAdapter) DefaultBuildCoordinator(org.jboss.pnc.coordinator.builder.DefaultBuildCoordinator) Test(org.junit.Test)

Aggregations

SystemConfig (org.jboss.pnc.common.json.moduleconfig.SystemConfig)13 Test (org.junit.Test)9 BuildExecutionConfiguration (org.jboss.pnc.spi.executor.BuildExecutionConfiguration)6 Consumer (java.util.function.Consumer)5 CompletedBuild (org.jboss.pnc.spi.builddriver.CompletedBuild)5 RunningBuild (org.jboss.pnc.spi.builddriver.RunningBuild)5 BuildDriverException (org.jboss.pnc.spi.builddriver.exception.BuildDriverException)5 RunningEnvironment (org.jboss.pnc.spi.environment.RunningEnvironment)5 BuildExecutionSession (org.jboss.pnc.spi.executor.BuildExecutionSession)5 Mockito.doReturn (org.mockito.Mockito.doReturn)5 Mockito.mock (org.mockito.Mockito.mock)5 Logger (org.slf4j.Logger)5 LoggerFactory (org.slf4j.LoggerFactory)5 Status (org.jboss.pnc.buildagent.api.Status)4 TaskStatusUpdateEvent (org.jboss.pnc.buildagent.api.TaskStatusUpdateEvent)4 IOException (java.io.IOException)3 MethodHandles (java.lang.invoke.MethodHandles)3 Files (java.nio.file.Files)3 Path (java.nio.file.Path)3 ArrayBlockingQueue (java.util.concurrent.ArrayBlockingQueue)3