Search in sources :

Example 1 with BuildSetCallBack

use of org.jboss.pnc.coordinator.notifications.buildSetTask.BuildSetCallBack in project pnc by project-ncl.

the class BuildCoordinationTest method buildSetTaskCallbacksShouldBeCalled.

@Test
public void buildSetTaskCallbacksShouldBeCalled() throws DatastoreException, TimeoutException, InterruptedException, CoreException {
    BuildConfigurationSet buildConfigurationSet = TestEntitiesFactory.newBuildConfigurationSet();
    testProjectConfigurationBuilder.buildConfigurationWithDependencies(buildConfigurationSet);
    Set<BuildSetStatusChangedEvent> buildSetStatusChangedEvents = new HashSet<>();
    Consumer<BuildSetStatusChangedEvent> statusChangeEventConsumer = buildSetStatusChangedEvents::add;
    BuildSetCallBack buildSetCallBack = new BuildSetCallBack(buildConfigurationSet.getId(), statusChangeEventConsumer);
    log.info("Subscribing new listener for buildSetTask.id {}.", buildSetCallBack.getBuildSetConfigurationId());
    buildSetStatusNotifications.subscribe(buildSetCallBack);
    log.info("Running builds ...");
    BuildOptions buildOptions = new BuildOptions();
    buildOptions.setRebuildMode(RebuildMode.FORCE);
    buildCoordinator.build(buildConfigurationSet, TestEntitiesFactory.newUser(), buildOptions);
    Wait.forCondition(() -> contains(buildSetStatusChangedEvents, BuildSetStatus.NEW), 2000, ChronoUnit.MILLIS, () -> "Did not receive status update to NEW for task set. Received: " + buildSetStatusChangedEvents);
    Wait.forCondition(() -> contains(buildSetStatusChangedEvents, BuildSetStatus.DONE), 2000, ChronoUnit.MILLIS, () -> "Did not receive status update to DONE for task set. Received: " + buildSetStatusChangedEvents);
    assertEmptyQueue();
}
Also used : BuildConfigurationSet(org.jboss.pnc.model.BuildConfigurationSet) BuildOptions(org.jboss.pnc.spi.BuildOptions) BuildSetCallBack(org.jboss.pnc.coordinator.notifications.buildSetTask.BuildSetCallBack) BuildSetStatusChangedEvent(org.jboss.pnc.spi.events.BuildSetStatusChangedEvent) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 2 with BuildSetCallBack

use of org.jboss.pnc.coordinator.notifications.buildSetTask.BuildSetCallBack in project pnc by project-ncl.

the class BuildCoordinationTest method registerCallback.

private ObjectWrapper<BuildSetStatus> registerCallback(BuildConfigurationSet buildConfigurationSet) {
    ObjectWrapper<BuildSetStatus> lastBuildSetStatus = new ObjectWrapper<>();
    Consumer<BuildSetStatusChangedEvent> onStatusUpdate = (statusChangedEvent) -> {
        if (statusChangedEvent.getNewStatus().isCompleted()) {
            lastBuildSetStatus.set(statusChangedEvent.getNewStatus());
        }
    };
    BuildSetCallBack buildSetCallBack = new BuildSetCallBack(buildConfigurationSet.getId(), onStatusUpdate);
    buildSetStatusNotifications.subscribe(buildSetCallBack);
    return lastBuildSetStatus;
}
Also used : BuildOptions(org.jboss.pnc.spi.BuildOptions) BuildConfigSetRecord(org.jboss.pnc.model.BuildConfigSetRecord) BuildSetStatus(org.jboss.pnc.spi.BuildSetStatus) Arquillian(org.jboss.arquillian.junit.Arquillian) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) RunWith(org.junit.runner.RunWith) LoggerFactory(org.slf4j.LoggerFactory) BuildConfigurationSet(org.jboss.pnc.model.BuildConfigurationSet) TimeoutException(java.util.concurrent.TimeoutException) WITH_DATASTORE(org.jboss.pnc.coordinator.test.BuildCoordinatorDeployments.Options.WITH_DATASTORE) BuildSetStatusNotifications(org.jboss.pnc.coordinator.notifications.buildSetTask.BuildSetStatusNotifications) RebuildMode(org.jboss.pnc.enums.RebuildMode) DatastoreMock(org.jboss.pnc.mock.datastore.DatastoreMock) Inject(javax.inject.Inject) HashSet(java.util.HashSet) BuildSetTask(org.jboss.pnc.spi.coordinator.BuildSetTask) BuildQueue(org.jboss.pnc.coordinator.builder.BuildQueue) Logger(org.slf4j.Logger) WITH_BPM(org.jboss.pnc.coordinator.test.BuildCoordinatorDeployments.Options.WITH_BPM) BuildCoordinator(org.jboss.pnc.spi.coordinator.BuildCoordinator) Collection(java.util.Collection) DatastoreException(org.jboss.pnc.spi.datastore.DatastoreException) Set(java.util.Set) Test(org.junit.Test) BuildRecord(org.jboss.pnc.model.BuildRecord) BuildStatus(org.jboss.pnc.enums.BuildStatus) Collectors(java.util.stream.Collectors) BuildSetCallBack(org.jboss.pnc.coordinator.notifications.buildSetTask.BuildSetCallBack) TestProjectConfigurationBuilder(org.jboss.pnc.mock.model.builders.TestProjectConfigurationBuilder) Consumer(java.util.function.Consumer) ObjectWrapper(org.jboss.pnc.common.util.ObjectWrapper) CoreException(org.jboss.pnc.spi.exception.CoreException) ChronoUnit(java.time.temporal.ChronoUnit) Assertions.fail(org.assertj.core.api.Assertions.fail) Deployment(org.jboss.arquillian.container.test.api.Deployment) JavaArchive(org.jboss.shrinkwrap.api.spec.JavaArchive) TestEntitiesFactory(org.jboss.pnc.mock.model.builders.TestEntitiesFactory) BuildSetStatusChangedEvent(org.jboss.pnc.spi.events.BuildSetStatusChangedEvent) Optional(java.util.Optional) Assert(org.junit.Assert) Wait(org.jboss.pnc.test.util.Wait) BuildSetStatus(org.jboss.pnc.spi.BuildSetStatus) BuildSetCallBack(org.jboss.pnc.coordinator.notifications.buildSetTask.BuildSetCallBack) ObjectWrapper(org.jboss.pnc.common.util.ObjectWrapper) BuildSetStatusChangedEvent(org.jboss.pnc.spi.events.BuildSetStatusChangedEvent)

Aggregations

HashSet (java.util.HashSet)2 BuildSetCallBack (org.jboss.pnc.coordinator.notifications.buildSetTask.BuildSetCallBack)2 BuildConfigurationSet (org.jboss.pnc.model.BuildConfigurationSet)2 BuildOptions (org.jboss.pnc.spi.BuildOptions)2 BuildSetStatusChangedEvent (org.jboss.pnc.spi.events.BuildSetStatusChangedEvent)2 Test (org.junit.Test)2 ChronoUnit (java.time.temporal.ChronoUnit)1 Collection (java.util.Collection)1 Optional (java.util.Optional)1 Set (java.util.Set)1 TimeoutException (java.util.concurrent.TimeoutException)1 Consumer (java.util.function.Consumer)1 Collectors (java.util.stream.Collectors)1 Inject (javax.inject.Inject)1 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)1 Assertions.fail (org.assertj.core.api.Assertions.fail)1 Deployment (org.jboss.arquillian.container.test.api.Deployment)1 Arquillian (org.jboss.arquillian.junit.Arquillian)1 ObjectWrapper (org.jboss.pnc.common.util.ObjectWrapper)1 BuildQueue (org.jboss.pnc.coordinator.builder.BuildQueue)1