Search in sources :

Example 1 with TooLargeJob

use of io.camunda.zeebe.engine.processing.job.JobBatchCollector.TooLargeJob in project zeebe by camunda.

the class JobBatchCollectorTest method shouldActivateUpToMaxJobs.

@Test
void shouldActivateUpToMaxJobs() {
    // given
    final TypedRecord<JobBatchRecord> record = createRecord();
    final long scopeKey = state.getKeyGenerator().nextKey();
    final List<Job> jobs = Arrays.asList(createJob(scopeKey), createJob(scopeKey));
    record.getValue().setMaxJobsToActivate(1);
    // when
    final Either<TooLargeJob, Integer> result = collector.collectJobs(record);
    // then
    final JobBatchRecord batchRecord = record.getValue();
    EitherAssert.assertThat(result).as("should collect only the first job").right().isEqualTo(1);
    JobBatchRecordValueAssert.assertThat(batchRecord).hasJobKeys(jobs.get(0).key).isNotTruncated();
}
Also used : TooLargeJob(io.camunda.zeebe.engine.processing.job.JobBatchCollector.TooLargeJob) TooLargeJob(io.camunda.zeebe.engine.processing.job.JobBatchCollector.TooLargeJob) JobBatchRecord(io.camunda.zeebe.protocol.impl.record.value.job.JobBatchRecord) Test(org.junit.jupiter.api.Test)

Example 2 with TooLargeJob

use of io.camunda.zeebe.engine.processing.job.JobBatchCollector.TooLargeJob in project zeebe by camunda.

the class JobBatchCollectorTest method shouldTruncateBatchIfNoMoreCanBeWritten.

@Test
void shouldTruncateBatchIfNoMoreCanBeWritten() {
    // given
    final long variableScopeKey = state.getKeyGenerator().nextKey();
    final TypedRecord<JobBatchRecord> record = createRecord();
    final List<Job> jobs = Arrays.asList(createJob(variableScopeKey), createJob(variableScopeKey));
    final var toggle = new AtomicBoolean(true);
    // when - set up the evaluator to only accept the first job
    lengthEvaluator.canWriteEventOfLength = (length) -> toggle.getAndSet(false);
    final Either<TooLargeJob, Integer> result = collector.collectJobs(record);
    // then
    final JobBatchRecord batchRecord = record.getValue();
    EitherAssert.assertThat(result).as("should have activated only one job successfully").right().isEqualTo(1);
    JobBatchRecordValueAssert.assertThat(batchRecord).hasOnlyJobKeys(jobs.get(0).key).isTruncated();
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) TooLargeJob(io.camunda.zeebe.engine.processing.job.JobBatchCollector.TooLargeJob) TooLargeJob(io.camunda.zeebe.engine.processing.job.JobBatchCollector.TooLargeJob) JobBatchRecord(io.camunda.zeebe.protocol.impl.record.value.job.JobBatchRecord) Test(org.junit.jupiter.api.Test)

Example 3 with TooLargeJob

use of io.camunda.zeebe.engine.processing.job.JobBatchCollector.TooLargeJob in project zeebe by zeebe-io.

the class JobBatchActivateProcessor method activateJobs.

private void activateJobs(final TypedRecord<JobBatchRecord> record) {
    final JobBatchRecord value = record.getValue();
    final long jobBatchKey = keyGenerator.nextKey();
    final Either<TooLargeJob, Integer> result = jobBatchCollector.collectJobs(record);
    final var activatedJobCount = result.getOrElse(0);
    result.ifLeft(largeJob -> raiseIncidentJobTooLargeForMessageSize(largeJob.key(), largeJob.record()));
    activateJobBatch(record, value, jobBatchKey, activatedJobCount);
}
Also used : TooLargeJob(io.camunda.zeebe.engine.processing.job.JobBatchCollector.TooLargeJob) JobBatchRecord(io.camunda.zeebe.protocol.impl.record.value.job.JobBatchRecord)

Example 4 with TooLargeJob

use of io.camunda.zeebe.engine.processing.job.JobBatchCollector.TooLargeJob in project zeebe by zeebe-io.

the class JobBatchCollectorTest method shouldActivateUpToMaxJobs.

@Test
void shouldActivateUpToMaxJobs() {
    // given
    final TypedRecord<JobBatchRecord> record = createRecord();
    final long scopeKey = state.getKeyGenerator().nextKey();
    final List<Job> jobs = Arrays.asList(createJob(scopeKey), createJob(scopeKey));
    record.getValue().setMaxJobsToActivate(1);
    // when
    final Either<TooLargeJob, Integer> result = collector.collectJobs(record);
    // then
    final JobBatchRecord batchRecord = record.getValue();
    EitherAssert.assertThat(result).as("should collect only the first job").right().isEqualTo(1);
    JobBatchRecordValueAssert.assertThat(batchRecord).hasJobKeys(jobs.get(0).key).isNotTruncated();
}
Also used : TooLargeJob(io.camunda.zeebe.engine.processing.job.JobBatchCollector.TooLargeJob) TooLargeJob(io.camunda.zeebe.engine.processing.job.JobBatchCollector.TooLargeJob) JobBatchRecord(io.camunda.zeebe.protocol.impl.record.value.job.JobBatchRecord) Test(org.junit.jupiter.api.Test)

Example 5 with TooLargeJob

use of io.camunda.zeebe.engine.processing.job.JobBatchCollector.TooLargeJob in project zeebe by zeebe-io.

the class JobBatchCollectorTest method shouldTruncateBatchIfNoMoreCanBeWritten.

@Test
void shouldTruncateBatchIfNoMoreCanBeWritten() {
    // given
    final long variableScopeKey = state.getKeyGenerator().nextKey();
    final TypedRecord<JobBatchRecord> record = createRecord();
    final List<Job> jobs = Arrays.asList(createJob(variableScopeKey), createJob(variableScopeKey));
    final var toggle = new AtomicBoolean(true);
    // when - set up the evaluator to only accept the first job
    lengthEvaluator.canWriteEventOfLength = (length) -> toggle.getAndSet(false);
    final Either<TooLargeJob, Integer> result = collector.collectJobs(record);
    // then
    final JobBatchRecord batchRecord = record.getValue();
    EitherAssert.assertThat(result).as("should have activated only one job successfully").right().isEqualTo(1);
    JobBatchRecordValueAssert.assertThat(batchRecord).hasOnlyJobKeys(jobs.get(0).key).isTruncated();
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) TooLargeJob(io.camunda.zeebe.engine.processing.job.JobBatchCollector.TooLargeJob) TooLargeJob(io.camunda.zeebe.engine.processing.job.JobBatchCollector.TooLargeJob) JobBatchRecord(io.camunda.zeebe.protocol.impl.record.value.job.JobBatchRecord) Test(org.junit.jupiter.api.Test)

Aggregations

TooLargeJob (io.camunda.zeebe.engine.processing.job.JobBatchCollector.TooLargeJob)12 JobBatchRecord (io.camunda.zeebe.protocol.impl.record.value.job.JobBatchRecord)12 Test (org.junit.jupiter.api.Test)9 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)3