Example usage for org.apache.commons.lang3.mutable MutableObject getValue

List of usage examples for org.apache.commons.lang3.mutable MutableObject getValue

Introduction

In this page you can find the example usage for org.apache.commons.lang3.mutable MutableObject getValue.

Prototype

@Override
public T getValue() 

Source Link

Document

Gets the value.

Usage

From source file:com.romeikat.datamessie.core.processing.task.documentProcessing.DocumentsProcessingTask.java

private void prepareForNextIteration(final TaskExecution taskExecution,
        final MutableObject<LocalDate> downloadedDate, final List<Document> documentsToProcess)
        throws TaskCancelledException {
    // No documents to process due to an error while loading
    final boolean errorOccurred = documentsToProcess == null;
    if (errorOccurred) {
        // In case of an error, wait and continue with same downloaded date
        sessionProvider.closeStatelessSession();
        taskExecution.checkpoint(pause);

        // Next download date to be processed is the same
        return;//from w  w  w  . j  a v  a2 s  . c  o m
    }

    // No documents to process for that downloaded date
    final boolean noDocumentsToProcess = documentsToProcess.isEmpty();
    if (noDocumentsToProcess) {
        // Determine next downloaded date
        final LocalDate previousDownloadDate = downloadedDate.getValue();
        final LocalDate nextDownloadedDate = getNextDownloadedDate(previousDownloadDate);

        // Current date is reached
        final boolean isCurrentDate = previousDownloadDate.equals(nextDownloadedDate);
        if (isCurrentDate) {
            // Pause
            sessionProvider.closeStatelessSession();
            taskExecution.checkpoint(pause);
            // Next downloaded date to be processed is the same
        }
        // Current date is not yet reached
        else {
            // Next downloaded date to be processed is the next day
            downloadedDate.setValue(nextDownloadedDate);
        }
        return;
    }

    // No more documents to process for that downloaded date
    final boolean noMoreDocumentsToProcess = documentsToProcess.size() < batchSize;
    if (noMoreDocumentsToProcess) {
        // Increase download date
        // Determine next downloaded date
        final LocalDate previousDownloadDate = downloadedDate.getValue();
        final LocalDate nextDownloadedDate = getNextDownloadedDate(previousDownloadDate);

        // Current date is reached
        final boolean isCurrentDate = previousDownloadDate.equals(nextDownloadedDate);
        if (isCurrentDate) {
            // Pause
            sessionProvider.closeStatelessSession();
            taskExecution.checkpoint(pause);
            // Next downloaded date to be processed is the same
        }
        // Current date is not yet reached
        else {
            // Next downloaded date to be processed is the next day
            downloadedDate.setValue(nextDownloadedDate);
        }
    }
}

From source file:fr.duminy.jbackup.core.JBackupImplTest.java

@Test
public void testBackup_withCancellable() throws Throwable {
    // prepare test
    final BackupConfiguration config = createConfiguration();
    final MutableBoolean taskStarted = new MutableBoolean(false);
    final Task mockBackupTask = createAlwaysWaitingTask(Task.class, taskStarted);
    final MutableObject<Cancellable> actualCancellable = new MutableObject<>();
    final MutableObject<TaskListener> actualListener = new MutableObject<>();
    JBackupImpl jBackup = spy(new JBackupImpl() {
        @Override//from w ww. j a v a2s.co  m
        Task createBackupTask(BackupConfiguration config, TaskListener listener, Cancellable cancellable) {
            actualListener.setValue(listener);
            actualCancellable.setValue(cancellable);
            return mockBackupTask;
        }
    });

    // test
    try {
        Future<Void> future = jBackup.backup(config);

        // wait task is actually started
        waitTaskStarted(taskStarted, actualCancellable);

        assertThat(actualCancellable.getValue()).as("cancellable").isNotNull();
        assertThat(actualCancellable.getValue().isCancelled()).as("cancelled").isFalse();

        future.cancel(true);
        assertThat(actualCancellable.getValue().isCancelled()).as("cancelled").isTrue();
    } finally {
        jBackup.shutdown(null);
    }

    // assertions
    InOrder inOrder = inOrder(mockBackupTask, jBackup);
    inOrder.verify(jBackup, times(1)).backup(eq(config)); // called above
    inOrder.verify(jBackup, times(1)).createBackupTask(eq(config), eq(actualListener.getValue()),
            eq(actualCancellable.getValue()));
    inOrder.verify(mockBackupTask, times(1)).call();
    inOrder.verify(jBackup, times(1)).shutdown(isNull(TerminationListener.class)); // called above
    inOrder.verifyNoMoreInteractions();
}

From source file:com.jayway.restassured.itest.java.HttpClientConfigITest.java

@Test
public void http_client_config_allows_specifying_that_the_http_client_instance_is_reused_in_multiple_requests() {
    final MutableObject<HttpClient> client1 = new MutableObject<HttpClient>();
    final MutableObject<HttpClient> client2 = new MutableObject<HttpClient>();

    RestAssured.config = newConfig().httpClient(httpClientConfig().reuseHttpClientInstance());

    // When//from   w ww.ja  va 2 s .  c  o  m
    try {
        given().param("url", "/hello").filter(new Filter() {
            public Response filter(FilterableRequestSpecification requestSpec,
                    FilterableResponseSpecification responseSpec, FilterContext ctx) {
                client1.setValue(requestSpec.getHttpClient());
                return ctx.next(requestSpec, responseSpec);
            }
        }).expect().body("hello", equalTo("Hello Scalatra")).when().get("/redirect");

        given().header("name", "value").filter((requestSpec, responseSpec, ctx) -> {
            client2.setValue(requestSpec.getHttpClient());
            return ctx.next(requestSpec, responseSpec);
        }).when().post("/reflect");
    } finally {
        RestAssured.reset();
    }

    assertThat(client1.getValue(), sameInstance(client2.getValue()));
}

From source file:io.restassured.itest.java.HttpClientConfigITest.java

@Test
public void http_client_config_allows_specifying_that_the_http_client_instance_is_reused_in_multiple_requests() {
    final MutableObject<HttpClient> client1 = new MutableObject<HttpClient>();
    final MutableObject<HttpClient> client2 = new MutableObject<HttpClient>();

    RestAssured.config = RestAssuredConfig.newConfig()
            .httpClient(HttpClientConfig.httpClientConfig().reuseHttpClientInstance());

    // When/*w w  w  .jav a 2 s. c  o  m*/
    try {
        given().param("url", "/hello").filter(new Filter() {
            public Response filter(FilterableRequestSpecification requestSpec,
                    FilterableResponseSpecification responseSpec, FilterContext ctx) {
                client1.setValue(requestSpec.getHttpClient());
                return ctx.next(requestSpec, responseSpec);
            }
        }).expect().body("hello", equalTo("Hello Scalatra")).when().get("/redirect");

        given().header("name", "value").filter((requestSpec, responseSpec, ctx) -> {
            client2.setValue(requestSpec.getHttpClient());
            return ctx.next(requestSpec, responseSpec);
        }).when().post("/reflect");
    } finally {
        RestAssured.reset();
    }

    assertThat(client1.getValue(), sameInstance(client2.getValue()));
}

From source file:fr.duminy.jbackup.core.JBackupImplTest.java

@Test
public void testRestore_withCancellable() throws Throwable {
    // prepare test
    final Path archive = tempFolder.newFolder().toPath().resolve("archive.zip");
    final Path targetDirectory = tempFolder.newFolder().toPath();
    final BackupConfiguration config = createConfiguration();
    final MutableBoolean taskStarted = new MutableBoolean(false);
    final Task mockRestoreTask = createAlwaysWaitingTask(Task.class, taskStarted);
    final MutableObject<Cancellable> actualCancellable = new MutableObject<>();
    final MutableObject<TaskListener> actualListener = new MutableObject<>();
    JBackupImpl jBackup = spy(new JBackupImpl() {
        @Override/*w  ww  .  j  av a 2 s.c  o  m*/
        Task createRestoreTask(BackupConfiguration config, Path archive, Path targetDirectory,
                TaskListener listener, Cancellable cancellable) {
            actualListener.setValue(listener);
            actualCancellable.setValue(cancellable);
            return mockRestoreTask;
        }
    });

    // test
    try {
        Future<Void> future = jBackup.restore(config, archive, targetDirectory);

        // wait task is actually started
        waitTaskStarted(taskStarted, actualCancellable);

        assertThat(actualCancellable.getValue()).as("cancellable").isNotNull();
        assertThat(actualCancellable.getValue().isCancelled()).as("cancelled").isFalse();

        future.cancel(true);
        assertThat(actualCancellable.getValue().isCancelled()).as("cancelled").isTrue();
    } finally {
        jBackup.shutdown(null);
    }

    // assertions
    InOrder inOrder = inOrder(mockRestoreTask, jBackup);
    inOrder.verify(jBackup, times(1)).restore(eq(config), eq(archive), eq(targetDirectory)); // called above
    inOrder.verify(jBackup, times(1)).createRestoreTask(eq(config), eq(archive), eq(targetDirectory),
            eq(actualListener.getValue()), eq(actualCancellable.getValue()));
    inOrder.verify(mockRestoreTask, times(1)).call();
    inOrder.verify(jBackup, times(1)).shutdown(isNull(TerminationListener.class)); // called above
    inOrder.verifyNoMoreInteractions();
}

From source file:fr.duminy.jbackup.core.JBackupImplTest.java

private void testBackup(ProgressListener listener) throws Throwable {
    final BackupConfiguration config = createConfiguration();
    final Task mockBackupTask = mock(Task.class);
    final MutableObject<TaskListener> actualTaskListener = new MutableObject<>();
    JBackupImpl jBackup = spy(new JBackupImpl() {
        @Override/*w w  w  .  ja v a 2s. c  om*/
        Task createBackupTask(BackupConfiguration config, TaskListener listener, Cancellable cancellable) {
            actualTaskListener.setValue(listener);
            return mockBackupTask;
        }
    });

    try {
        if (listener != null) {
            jBackup.addProgressListener(config.getName(), listener);
        }
        Future<Void> future = jBackup.backup(config);
        waitResult(future);
    } finally {
        jBackup.shutdown(null);
    }

    verify(jBackup, times(1)).backup(eq(config)); // called above
    verify(jBackup, times(1)).shutdown(isNull(TerminationListener.class)); // called above
    verify(jBackup, times(1)).createBackupTask(eq(config), eq(actualTaskListener.getValue()),
            notNull(Cancellable.class));
    verify(mockBackupTask, times(1)).call();
    if (listener != null) {
        verify(jBackup, times(1)).addProgressListener(eq(config.getName()), eq(listener));
    }
    verifyNoMoreInteractions(mockBackupTask, jBackup);
}

From source file:com.github.jrh3k5.mojo.flume.AbstractFlumeAgentsMojoTest.java

/**
 * Test the copying of Flume plugins.// w  ww . j a v  a2 s  .  c  o m
 * 
 * @throws Exception
 *             If any errors occur during the test run.
 */
@Test
public void testCopyFlumePlugins() throws Exception {
    final File flumeDirectory = createTestDirectory();
    FileUtils.forceMkdir(flumeDirectory);

    // Build the file that is to be copied and the temporarily-staged .tar file from it
    final String randomUuid = UUID.randomUUID().toString();
    final File flumePluginFile = new File(flumeDirectory, randomUuid + ".tar.gz");
    final File flumePluginTarFile = new File(flumeDirectory, randomUuid + ".tar");

    // Create a collection that will be used to inject the "discovered" Flume plugin dependencies
    final Artifact flumePluginArtifact = mock(Artifact.class);
    when(flumePluginArtifact.getFile()).thenReturn(flumePluginFile);
    final Collection<Artifact> flumePluginDependencies = Collections.singleton(flumePluginArtifact);

    // So that we don't have to *actually* test the untarring/unzipping here
    mockStatic(ArchiveUtils.class);

    final MutableObject<Agent> capturedAgent = new MutableObject<Agent>();
    final ConcreteMojo toTest = setParameters(new ConcreteMojo() {
        @Override
        Collection<Artifact> getFlumePluginDependencies(Agent agent) throws IOException {
            capturedAgent.setValue(agent);
            return flumePluginDependencies;
        }
    });
    // Without this, the method will think there are no Flume plugins to copy
    final FlumePlugin flumePlugin = mock(FlumePlugin.class);
    when(agent.getFlumePlugins()).thenReturn(Collections.singletonList(flumePlugin));

    // Actually invoke the method to be tested
    toTest.copyFlumePlugins(agent, flumeDirectory);

    final File expectedPluginsDir = new File(flumeDirectory, "plugins.d");
    // The "discovered" Flume plugin should have been "unzipped" and "untarred"
    verifyStatic();
    ArchiveUtils.gunzipFile(flumePluginFile.toURI().toURL(), flumePluginTarFile);
    ArchiveUtils.untarFile(flumePluginTarFile, expectedPluginsDir);

    assertThat(capturedAgent.getValue()).isEqualTo(agent);
}

From source file:com.jayway.restassured.itest.java.HttpClientConfigITest.java

@Test
public void local_http_client_config_doesnt_reuse_static_http_client_instance_when_local_config_specifies_reuse() {
    final MutableObject<HttpClient> client1 = new MutableObject<HttpClient>();
    final MutableObject<HttpClient> client2 = new MutableObject<HttpClient>();

    RestAssured.config = newConfig().httpClient(httpClientConfig().reuseHttpClientInstance());

    // When/*from w ww.  j a v a 2 s . c om*/
    try {
        given().param("url", "/hello").filter(new Filter() {
            public Response filter(FilterableRequestSpecification requestSpec,
                    FilterableResponseSpecification responseSpec, FilterContext ctx) {
                client1.setValue(requestSpec.getHttpClient());
                return ctx.next(requestSpec, responseSpec);
            }
        }).expect().body("hello", equalTo("Hello Scalatra")).when().get("/redirect");

        given().config(newConfig().httpClient(httpClientConfig().reuseHttpClientInstance()))
                .header("name", "value").filter(new Filter() {
                    public Response filter(FilterableRequestSpecification requestSpec,
                            FilterableResponseSpecification responseSpec, FilterContext ctx) {
                        client2.setValue(requestSpec.getHttpClient());
                        return ctx.next(requestSpec, responseSpec);
                    }
                }).when().post("/reflect");
    } finally {
        RestAssured.reset();
    }

    assertThat(client1.getValue(), not(sameInstance(client2.getValue())));
}

From source file:fr.duminy.jbackup.core.JBackupImplTest.java

private void testRestore(ProgressListener listener) throws Throwable {
    final Path archive = tempFolder.newFolder().toPath().resolve("archive.zip");
    final Path targetDirectory = tempFolder.newFolder().toPath();
    final BackupConfiguration config = createConfiguration();
    final Task mockRestoreTask = mock(Task.class);
    final MutableObject<TaskListener> actualTaskListener = new MutableObject<>();
    JBackupImpl jBackup = spy(new JBackupImpl() {
        @Override/*from   w w  w .j  av  a2s  .  co m*/
        Task createRestoreTask(BackupConfiguration config, Path archive, Path targetDirectory,
                TaskListener taskListener, Cancellable cancellable) {
            actualTaskListener.setValue(taskListener);
            return mockRestoreTask;
        }
    });

    try {
        if (listener != null) {
            jBackup.addProgressListener(config.getName(), listener);
        }
        Future<Void> future = jBackup.restore(config, archive, targetDirectory);
        waitResult(future);
    } finally {
        jBackup.shutdown(null);
    }

    verify(jBackup, times(1)).restore(eq(config), eq(archive), eq(targetDirectory)); // called above
    verify(jBackup, times(1)).shutdown(isNull(TerminationListener.class)); // called above
    verify(jBackup, times(1)).createRestoreTask(eq(config), eq(archive), eq(targetDirectory),
            eq(actualTaskListener.getValue()), notNull(Cancellable.class));
    verify(mockRestoreTask, times(1)).call();
    if (listener != null) {
        verify(jBackup, times(1)).addProgressListener(eq(config.getName()), eq(listener));
    }
    verifyNoMoreInteractions(mockRestoreTask, jBackup);
}

From source file:io.restassured.itest.java.HttpClientConfigITest.java

@Test
public void local_http_client_config_doesnt_reuse_static_http_client_instance_when_local_config_specifies_reuse() {
    final MutableObject<HttpClient> client1 = new MutableObject<HttpClient>();
    final MutableObject<HttpClient> client2 = new MutableObject<HttpClient>();

    RestAssured.config = RestAssuredConfig.newConfig()
            .httpClient(HttpClientConfig.httpClientConfig().reuseHttpClientInstance());

    // When//from www  .  ja v  a 2 s.  c o  m
    try {
        given().param("url", "/hello").filter(new Filter() {
            public Response filter(FilterableRequestSpecification requestSpec,
                    FilterableResponseSpecification responseSpec, FilterContext ctx) {
                client1.setValue(requestSpec.getHttpClient());
                return ctx.next(requestSpec, responseSpec);
            }
        }).expect().body("hello", equalTo("Hello Scalatra")).when().get("/redirect");

        given().config(RestAssuredConfig.newConfig()
                .httpClient(HttpClientConfig.httpClientConfig().reuseHttpClientInstance()))
                .header("name", "value").filter(new Filter() {
                    public Response filter(FilterableRequestSpecification requestSpec,
                            FilterableResponseSpecification responseSpec, FilterContext ctx) {
                        client2.setValue(requestSpec.getHttpClient());
                        return ctx.next(requestSpec, responseSpec);
                    }
                }).when().post("/reflect");
    } finally {
        RestAssured.reset();
    }

    assertThat(client1.getValue(), not(sameInstance(client2.getValue())));
}