@Test public void testReplaceTask() { JobStore store = getJobStore(); Job<BatchJobExt> job = createBatchJobObject(); store.init().await(); store.storeJob(job).await(); Pair<List<Job<?>>, Integer> jobsAndErrors = store.retrieveJobs().toBlocking().first(); assertThat(jobsAndErrors.getLeft().get(0)).isEqualTo(job); Task firstTask = createTaskObject(job); store.storeTask(firstTask).await(); Task retrievedTask = store.retrieveTask(firstTask.getId()).toBlocking().first(); assertThat(firstTask).isEqualTo(retrievedTask); Task secondTask = createTaskObject(job); store.replaceTask(firstTask, secondTask).await(); Pair<List<Task>, Integer> tasks = store.retrieveTasksForJob(job.getId()).toBlocking().first(); assertThat(tasks.getLeft()).hasSize(1); assertThat(tasks.getRight()).isEqualTo(0); assertThat(tasks.getLeft().get(0)).isEqualTo(secondTask); }
@Override public Completable replaceTask(Task oldTask, Task newTask) { return Observable.fromCallable((Callable<Statement>) () -> { String jobId = newTask.getJobId(); checkIfJobIsActive(jobId); String taskId = newTask.getId(); String taskJsonString = ObjectMappers.writeValueAsString(mapper, newTask); BatchStatement batchStatement = getArchiveTaskBatchStatement(oldTask); Statement insertTaskStatement = insertActiveTaskStatement.bind(taskId, taskJsonString); Statement insertTaskIdStatement = insertActiveTaskIdStatement.bind(jobId, taskId); batchStatement.add(insertTaskStatement); batchStatement.add(insertTaskIdStatement); return batchStatement; }).flatMap(this::execute).toCompletable(); }
CassandraJobStore implements JobStore { @Override public Completable replaceTask(Task oldTask, Task newTask) { return Observable.fromCallable((Callable<Statement>) () -> { String jobId = newTask.getJobId(); checkIfJobIsActive(jobId); String taskId = newTask.getId(); String taskJsonString = ObjectMappers.writeValueAsString(mapper, newTask); BatchStatement batchStatement = getArchiveTaskBatchStatement(oldTask); Statement insertTaskStatement = insertActiveTaskStatement.bind(taskId, taskJsonString); Statement insertTaskIdStatement = insertActiveTaskIdStatement.bind(jobId, taskId); batchStatement.add(insertTaskStatement); batchStatement.add(insertTaskIdStatement); return batchStatement; }).flatMap(this::execute).toCompletable(); } }
CassandraJobStore implements JobStore { @Override public Completable replaceTask(Task oldTask, Task newTask) { return Observable.fromCallable((Callable<Statement>) () -> { String jobId = newTask.getJobId(); checkIfJobIsActive(jobId); String taskId = newTask.getId(); String taskJsonString = ObjectMappers.writeValueAsString(mapper, newTask); BatchStatement batchStatement = getArchiveTaskBatchStatement(oldTask); Statement insertTaskStatement = insertActiveTaskStatement.bind(taskId, taskJsonString); Statement insertTaskIdStatement = insertActiveTaskIdStatement.bind(jobId, taskId); batchStatement.add(insertTaskStatement); batchStatement.add(insertTaskIdStatement); return batchStatement; }).flatMap(this::execute).toCompletable(); } @Inject  CassandraJobStore(CassandraStoreConfiguration configuration,
                             Session session,
                             TitusRuntime titusRuntime);   CassandraJobStore(CassandraStoreConfiguration configuration,
                      Session session,
                      TitusRuntime titusRuntime,
                      ObjectMapper mapper,
                      int initialBucketCount,
                      int maxBucketSize); }
CassandraJobStore implements JobStore { @Override public Completable replaceTask(Task oldTask, Task newTask) { return Observable.fromCallable((Callable<Statement>) () -> { String jobId = newTask.getJobId(); checkIfJobIsActive(jobId); String taskId = newTask.getId(); String taskJsonString = ObjectMappers.writeValueAsString(mapper, newTask); BatchStatement batchStatement = getArchiveTaskBatchStatement(oldTask); Statement insertTaskStatement = insertActiveTaskStatement.bind(taskId, taskJsonString); Statement insertTaskIdStatement = insertActiveTaskIdStatement.bind(jobId, taskId); batchStatement.add(insertTaskStatement); batchStatement.add(insertTaskIdStatement); return batchStatement; }).flatMap(this::execute).toCompletable(); } @Inject  CassandraJobStore(CassandraStoreConfiguration configuration,
                             Session session,
                             TitusRuntime titusRuntime);   CassandraJobStore(CassandraStoreConfiguration configuration,
                      Session session,
                      TitusRuntime titusRuntime,
                      ObjectMapper mapper,
                      int initialBucketCount,
                      int maxBucketSize); @Override Completable init(); @Override Observable<Pair<List<Job<?>>, Integer>> retrieveJobs(); @Override Observable<Job<?>> retrieveJob(String jobId); @Override Completable storeJob(Job job); @Override Completable updateJob(Job job); @Override Completable deleteJob(Job job); @Override Observable<Pair<List<Task>, Integer>> retrieveTasksForJob(String jobId); @Override Observable<Task> retrieveTask(String taskId); @Override Completable storeTask(Task task); @Override Completable updateTask(Task task); @Override Completable replaceTask(Task oldTask, Task newTask); @Override Completable moveTask(Job jobFrom, Job jobTo, Task taskAfter); @Override Completable deleteTask(Task task); @Override Observable<Job<?>> retrieveArchivedJob(String jobId); @Override Observable<Task> retrieveArchivedTasksForJob(String jobId); @Override Observable<Task> retrieveArchivedTask(String taskId); }
CassandraJobStore implements JobStore { @Override public Completable replaceTask(Task oldTask, Task newTask) { return Observable.fromCallable((Callable<Statement>) () -> { String jobId = newTask.getJobId(); checkIfJobIsActive(jobId); String taskId = newTask.getId(); String taskJsonString = ObjectMappers.writeValueAsString(mapper, newTask); BatchStatement batchStatement = getArchiveTaskBatchStatement(oldTask); Statement insertTaskStatement = insertActiveTaskStatement.bind(taskId, taskJsonString); Statement insertTaskIdStatement = insertActiveTaskIdStatement.bind(jobId, taskId); batchStatement.add(insertTaskStatement); batchStatement.add(insertTaskIdStatement); return batchStatement; }).flatMap(this::execute).toCompletable(); } @Inject  CassandraJobStore(CassandraStoreConfiguration configuration,
                             Session session,
                             TitusRuntime titusRuntime);   CassandraJobStore(CassandraStoreConfiguration configuration,
                      Session session,
                      TitusRuntime titusRuntime,
                      ObjectMapper mapper,
                      int initialBucketCount,
                      int maxBucketSize); @Override Completable init(); @Override Observable<Pair<List<Job<?>>, Integer>> retrieveJobs(); @Override Observable<Job<?>> retrieveJob(String jobId); @Override Completable storeJob(Job job); @Override Completable updateJob(Job job); @Override Completable deleteJob(Job job); @Override Observable<Pair<List<Task>, Integer>> retrieveTasksForJob(String jobId); @Override Observable<Task> retrieveTask(String taskId); @Override Completable storeTask(Task task); @Override Completable updateTask(Task task); @Override Completable replaceTask(Task oldTask, Task newTask); @Override Completable moveTask(Job jobFrom, Job jobTo, Task taskAfter); @Override Completable deleteTask(Task task); @Override Observable<Job<?>> retrieveArchivedJob(String jobId); @Override Observable<Task> retrieveArchivedTasksForJob(String jobId); @Override Observable<Task> retrieveArchivedTask(String taskId);  }