Skip to content

Commit

Permalink
deps: update to Guava 29.0-jre (#837)
Browse files Browse the repository at this point in the history
* update to Guava 28.2-jre

* trivial change--http-->https-->to force CI to run again
  • Loading branch information
elharo committed Apr 16, 2020
1 parent b5d9a2f commit 4db90e1
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 25 deletions.
4 changes: 2 additions & 2 deletions appengine-plugins-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

<organization>
<name>Google LLC</name>
<url>http://www.google.com</url>
<url>https://www.google.com</url>
</organization>

<licenses>
Expand Down Expand Up @@ -67,7 +67,7 @@
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>28.1-jre</version>
<version>28.2-jre</version>
</dependency>
<dependency>
<groupId>org.yaml</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,10 @@ class AsyncByteConsumer implements AsyncStreamSaver {
@Override
public void handleStream(final InputStream inputStream) {
if (executorService.isShutdown()) {
throw new IllegalStateException("Cannot re-use " + this.getClass().getName());
throw new IllegalStateException("Cannot reuse " + this.getClass().getName());
}
result.setFuture(executorService.submit(() -> consumeBytes(inputStream)));
ListenableFuture<String> submit = executorService.submit(() -> consumeBytes(inputStream));
result.setFuture(submit);
executorService.shutdown();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,12 @@
package com.google.cloud.tools.managedcloudsdk.command;

import com.google.common.util.concurrent.ListeningExecutorService;
import com.google.common.util.concurrent.MoreExecutors;
import com.google.common.util.concurrent.SettableFuture;
import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutorService;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
Expand All @@ -37,42 +38,50 @@ public class AsyncByteConsumerTest {
private final InputStream fakeInputStream =
new ByteArrayInputStream(TEST_STRING.getBytes(StandardCharsets.UTF_8));

@Mock private ListeningExecutorService mockExecutorService;
@Mock private ExecutorService executorService;
@Mock private ByteHandler mockByteHandler;
@Mock private InputStream mockInputStream;
@Mock private SettableFuture<String> mockFuture;

private SettableFuture<String> future = SettableFuture.create();

@Test
public void testHandleStream() {
Mockito.when(mockExecutorService.isShutdown()).thenReturn(false);
Mockito.when(executorService.isShutdown()).thenReturn(false);

ListeningExecutorService listeningExecutorService =
MoreExecutors.listeningDecorator(executorService);

new AsyncByteConsumer(mockByteHandler, mockExecutorService, mockFuture)
.handleStream(mockInputStream);
AsyncByteConsumer consumer =
new AsyncByteConsumer(mockByteHandler, listeningExecutorService, future);
consumer.handleStream(mockInputStream);

Mockito.verify(mockExecutorService).isShutdown();
Mockito.verify(mockExecutorService).submit(Mockito.<Callable<Object>>any());
Mockito.verify(mockExecutorService).shutdown();
Mockito.verifyNoMoreInteractions(mockExecutorService);
Mockito.verify(executorService).isShutdown();
Mockito.verify(executorService).execute(Mockito.<Runnable>any());
Mockito.verify(executorService).shutdown();
Mockito.verifyNoMoreInteractions(executorService);
}

@Test
public void testHandleStream_failIfReused() {
Mockito.when(mockExecutorService.isShutdown()).thenReturn(true);
Mockito.when(executorService.isShutdown()).thenReturn(true);
ListeningExecutorService listeningExecutorService =
MoreExecutors.listeningDecorator(executorService);

try {
new AsyncByteConsumer(mockByteHandler, mockExecutorService, mockFuture)
new AsyncByteConsumer(mockByteHandler, listeningExecutorService, future)
.handleStream(mockInputStream);
Assert.fail("IllegalStateException expected but not thrown");
} catch (IllegalStateException ex) {
// pass
Assert.assertEquals("Cannot re-use " + AsyncByteConsumer.class.getName(), ex.getMessage());
Assert.assertEquals("Cannot reuse " + AsyncByteConsumer.class.getName(), ex.getMessage());
}
}

@Test
public void testConsumeBytes() throws Exception {

new AsyncByteConsumer(mockByteHandler, mockExecutorService, mockFuture)
ListeningExecutorService listeningExecutorService =
MoreExecutors.listeningDecorator(executorService);
new AsyncByteConsumer(mockByteHandler, listeningExecutorService, future)
.consumeBytes(fakeInputStream);

ArgumentCaptor<byte[]> bytes = ArgumentCaptor.forClass(byte[].class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@

import com.google.cloud.tools.managedcloudsdk.process.ProcessExecutor;
import com.google.common.collect.ImmutableMap;
import com.google.common.util.concurrent.ListenableFuture;
import com.google.common.util.concurrent.AbstractFuture;
import com.google.common.util.concurrent.SettableFuture;
import java.io.IOException;
import java.nio.file.Path;
import java.util.Arrays;
Expand All @@ -45,9 +46,9 @@ public class CommandCallerTest {
@Mock private AsyncStreamSaver mockStdoutSaver;
@Mock private AsyncStreamSaver mockStderrSaver;
@Mock private AsyncStreamSaverFactory mockStreamSaverFactory;
@Mock private ListenableFuture<String> mockStdout;
@Mock private ListenableFuture<String> mockStderr;

private final SettableFuture<String> mockStdout = SettableFuture.create();
private final SettableFuture<String> mockStderr = SettableFuture.create();
private List<String> fakeCommand;
private Path fakeWorkingDirectory;
private Map<String, String> fakeEnvironment;
Expand All @@ -73,8 +74,9 @@ public void setUp() throws IOException, InterruptedException, ExecutionException
.thenReturn(0);
Mockito.when(mockStdoutSaver.getResult()).thenReturn(mockStdout);
Mockito.when(mockStderrSaver.getResult()).thenReturn(mockStderr);
Mockito.when(mockStdout.get()).thenReturn("stdout");
Mockito.when(mockStderr.get()).thenReturn("stderr");

mockStdout.set("stdout");
mockStderr.set("stderr");

testCommandCaller = new CommandCaller(() -> mockProcessExecutor, mockStreamSaverFactory);
}
Expand Down Expand Up @@ -143,7 +145,15 @@ public void testCall_ioException()
public void testCall_interruptedExceptionPassthrough()
throws CommandExecutionException, CommandExitException, ExecutionException,
InterruptedException, IOException {
Mockito.when(mockStdout.get()).thenThrow(InterruptedException.class);

AbstractFuture<String> future =
new AbstractFuture<String>() {
@Override
public String get() throws InterruptedException {
throw new InterruptedException();
}
};
Mockito.when(mockStdoutSaver.getResult()).thenReturn(future);

try {
testCommandCaller.call(fakeCommand, fakeWorkingDirectory, fakeEnvironment);
Expand Down

0 comments on commit 4db90e1

Please sign in to comment.