Search in sources :

Example 1 with Recipient

use of org.kie.kogito.jobs.service.model.job.Recipient in project kogito-apps by kiegroup.

the class BaseJobRepositoryTest method createAndSaveJob.

private void createAndSaveJob(String id) throws Exception {
    job = JobDetails.builder().id(id).trigger(// 
    new PointInTimeTrigger(System.currentTimeMillis(), null, null)).priority(1).recipient(new Recipient.HTTPRecipient("url")).build();
    tested().save(job).toCompletableFuture().get();
}
Also used : Recipient(org.kie.kogito.jobs.service.model.job.Recipient) PointInTimeTrigger(org.kie.kogito.timer.impl.PointInTimeTrigger)

Example 2 with Recipient

use of org.kie.kogito.jobs.service.model.job.Recipient in project kogito-apps by kiegroup.

the class RecipientMarshallerTest method unmarshall.

@Test
void unmarshall() {
    JsonObject jsonObject = new JsonObject().put("endpoint", "test").put("classType", Recipient.HTTPRecipient.class.getName());
    Recipient recipient = marshaller.unmarshall(jsonObject);
    assertEquals(new Recipient.HTTPRecipient("test"), recipient);
}
Also used : JsonObject(io.vertx.core.json.JsonObject) Recipient(org.kie.kogito.jobs.service.model.job.Recipient) Test(org.junit.jupiter.api.Test)

Example 3 with Recipient

use of org.kie.kogito.jobs.service.model.job.Recipient in project kogito-apps by kiegroup.

the class JobDetailsMarshaller method readFrom.

@Override
public JobDetails readFrom(ProtoStreamReader reader) throws IOException {
    String id = reader.readString("id");
    String correlationId = reader.readString("correlationId");
    JobStatus status = mapString(reader.readString("status"), JobStatus.class);
    ZonedDateTime lastUpdate = instantToZonedDateTime(reader.readInstant("lastUpdate"));
    Integer retries = reader.readInt("retries");
    Integer priority = reader.readInt("priority");
    Integer executionCounter = reader.readInt("executionCounter");
    String scheduledId = reader.readString("scheduledId");
    // serialize payload
    String payload = reader.readString("payload");
    Recipient recipient = reader.readObject("recipient", Recipient.class);
    Trigger trigger = reader.readObject("trigger", Trigger.class);
    JobDetails.Type type = mapString(reader.readString("type"), JobDetails.Type.class);
    return JobDetails.builder().id(id).correlationId(correlationId).status(status).lastUpdate(lastUpdate).retries(retries).priority(priority).executionCounter(executionCounter).scheduledId(scheduledId).payload(payload).recipient(recipient).trigger(trigger).type(type).build();
}
Also used : JobStatus(org.kie.kogito.jobs.service.model.JobStatus) Trigger(org.kie.kogito.timer.Trigger) DateUtil.instantToZonedDateTime(org.kie.kogito.jobs.service.utils.DateUtil.instantToZonedDateTime) ZonedDateTime(java.time.ZonedDateTime) Recipient(org.kie.kogito.jobs.service.model.job.Recipient) JobDetails(org.kie.kogito.jobs.service.model.job.JobDetails)

Example 4 with Recipient

use of org.kie.kogito.jobs.service.model.job.Recipient in project kogito-apps by kiegroup.

the class MongoDBJobRepositoryTest method setUp.

@BeforeEach
void setUp() {
    mongoClient = mock(ReactiveMongoClient.class);
    collection = mock(ReactiveMongoCollection.class);
    ReactiveMongoDatabase mongoDatabase = mock(ReactiveMongoDatabase.class);
    when(mongoClient.getDatabase(anyString())).thenReturn(mongoDatabase);
    when(mongoDatabase.getCollection(anyString())).thenReturn(collection);
    Uni uni = mock(Uni.class);
    Multi multi = mock(Multi.class);
    when(collection.findOneAndReplace(any(Bson.class), any(), any(FindOneAndReplaceOptions.class))).thenReturn(uni);
    when(collection.find(any(Bson.class))).thenReturn(multi);
    when(collection.findOneAndDelete(any(Bson.class))).thenReturn(uni);
    when(collection.find()).thenReturn(multi);
    when(collection.find(any(Bson.class), any(FindOptions.class))).thenReturn(multi);
    when(collection.createIndex(any())).thenReturn(uni);
    when(uni.map(any())).thenAnswer(invocationOnMock -> {
        jobDetailsMarshaller.unmarshall(marshalled);
        return uni;
    });
    when(uni.await()).thenReturn(mock(UniAwait.class));
    MultiCollect multiCollect = mock(MultiCollect.class);
    when(multi.collect()).thenReturn(multiCollect);
    when(multiCollect.first()).thenReturn(uni);
    when(multiCollect.with(any())).thenReturn(uni);
    when(multi.map(any())).thenAnswer(invocationOnMock -> {
        jobDetailsMarshaller.unmarshall(marshalled);
        return multi;
    });
    MultiConvert convertMulti = mock(MultiConvert.class);
    when(multi.emitOn(any())).thenReturn(multi);
    when(multi.convert()).thenReturn(convertMulti);
    Publisher publisher = mock(Publisher.class);
    when(convertMulti.toPublisher()).thenReturn(publisher);
    completableFuture = mock(CompletableFuture.class);
    UniConvert convert = mock(UniConvert.class);
    when(uni.emitOn(any())).thenReturn(uni);
    when(uni.convert()).thenReturn(convert);
    when(convert.toCompletionStage()).thenReturn(completableFuture);
    ZonedDateTime time = ZonedDateTime.now(DEFAULT_ZONE);
    PointInTimeTrigger trigger = new PointInTimeTrigger(time.toInstant().getEpochSecond(), null, null);
    Recipient recipient = new Recipient.HTTPRecipient("test");
    unmarshalled = new JobDetailsBuilder().id("test").trigger(trigger).recipient(recipient).build();
    marshalled = new JsonObject().put("id", "test");
    jobDetailsMarshaller = mock(JobDetailsMarshaller.class);
    when(jobDetailsMarshaller.marshall(any(JobDetails.class))).thenReturn(marshalled);
    when(jobDetailsMarshaller.unmarshall(any(JsonObject.class))).thenReturn(unmarshalled);
    mongoDBJobRepository = new MongoDBJobRepository(null, null, mongoClient, "test", jobDetailsMarshaller);
}
Also used : FindOptions(io.quarkus.mongodb.FindOptions) ReactiveMongoDatabase(io.quarkus.mongodb.reactive.ReactiveMongoDatabase) MultiConvert(io.smallrye.mutiny.groups.MultiConvert) JobDetailsMarshaller(org.kie.kogito.jobs.service.repository.marshaller.JobDetailsMarshaller) JsonObject(io.vertx.core.json.JsonObject) Multi(io.smallrye.mutiny.Multi) Recipient(org.kie.kogito.jobs.service.model.job.Recipient) Publisher(org.reactivestreams.Publisher) MultiCollect(io.smallrye.mutiny.groups.MultiCollect) PointInTimeTrigger(org.kie.kogito.timer.impl.PointInTimeTrigger) ReactiveMongoCollection(io.quarkus.mongodb.reactive.ReactiveMongoCollection) JobDetailsBuilder(org.kie.kogito.jobs.service.model.job.JobDetailsBuilder) JobDetails(org.kie.kogito.jobs.service.model.job.JobDetails) Bson(org.bson.conversions.Bson) UniAwait(io.smallrye.mutiny.groups.UniAwait) Uni(io.smallrye.mutiny.Uni) FindOneAndReplaceOptions(com.mongodb.client.model.FindOneAndReplaceOptions) ReactiveMongoClient(io.quarkus.mongodb.reactive.ReactiveMongoClient) CompletableFuture(java.util.concurrent.CompletableFuture) UniConvert(io.smallrye.mutiny.groups.UniConvert) ZonedDateTime(java.time.ZonedDateTime) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 5 with Recipient

use of org.kie.kogito.jobs.service.model.job.Recipient in project kogito-apps by kiegroup.

the class BaseJobRepositoryTest method testMergeCallbackEndpoint.

@Test
void testMergeCallbackEndpoint() throws Exception {
    String id = UUID.randomUUID().toString();
    createAndSaveJob(id);
    final String newCallbackEndpoint = "http://localhost/newcallback";
    final Recipient.HTTPRecipient recipient = new Recipient.HTTPRecipient(newCallbackEndpoint);
    final JobDetails toMerge = JobDetails.builder().id(id).recipient(recipient).build();
    JobDetails merged = tested().merge(id, toMerge).toCompletableFuture().get();
    assertThat(merged.getRecipient()).isEqualTo(recipient);
    assertThat(merged.getId()).isEqualTo(job.getId());
    assertThat(merged.getTrigger().hasNextFireTime()).isEqualTo(job.getTrigger().hasNextFireTime());
}
Also used : Recipient(org.kie.kogito.jobs.service.model.job.Recipient) JobDetails(org.kie.kogito.jobs.service.model.job.JobDetails) Test(org.junit.jupiter.api.Test)

Aggregations

Recipient (org.kie.kogito.jobs.service.model.job.Recipient)12 JsonObject (io.vertx.core.json.JsonObject)8 Test (org.junit.jupiter.api.Test)8 JobDetails (org.kie.kogito.jobs.service.model.job.JobDetails)7 PointInTimeTrigger (org.kie.kogito.timer.impl.PointInTimeTrigger)6 ZonedDateTime (java.time.ZonedDateTime)4 JobStatus (org.kie.kogito.jobs.service.model.JobStatus)3 Trigger (org.kie.kogito.timer.Trigger)3 Date (java.util.Date)2 BeforeEach (org.junit.jupiter.api.BeforeEach)2 FindOneAndReplaceOptions (com.mongodb.client.model.FindOneAndReplaceOptions)1 FindOptions (io.quarkus.mongodb.FindOptions)1 ReactiveMongoClient (io.quarkus.mongodb.reactive.ReactiveMongoClient)1 ReactiveMongoCollection (io.quarkus.mongodb.reactive.ReactiveMongoCollection)1 ReactiveMongoDatabase (io.quarkus.mongodb.reactive.ReactiveMongoDatabase)1 Multi (io.smallrye.mutiny.Multi)1 Uni (io.smallrye.mutiny.Uni)1 MultiCollect (io.smallrye.mutiny.groups.MultiCollect)1 MultiConvert (io.smallrye.mutiny.groups.MultiConvert)1 UniAwait (io.smallrye.mutiny.groups.UniAwait)1