List of usage examples for java.util.concurrent.atomic AtomicReference set
public final void set(V newValue)
From source file:org.elasticsearch.common.cli.CliToolTests.java
@Test public void testOK() throws Exception { Terminal terminal = new MockTerminal(); final AtomicReference<Boolean> executed = new AtomicReference<>(false); final NamedCommand cmd = new NamedCommand("cmd", terminal) { @Override//from ww w. ja va 2s . co m public CliTool.ExitStatus execute(Settings settings, Environment env) { executed.set(true); return CliTool.ExitStatus.OK; } }; SingleCmdTool tool = new SingleCmdTool("tool", terminal, cmd); int status = tool.execute(); assertStatus(status, CliTool.ExitStatus.OK); assertCommandHasBeenExecuted(executed); }
From source file:org.elasticsearch.common.cli.CliToolTests.java
@Test public void testUsageError() throws Exception { Terminal terminal = new MockTerminal(); final AtomicReference<Boolean> executed = new AtomicReference<>(false); final NamedCommand cmd = new NamedCommand("cmd", terminal) { @Override/*from w w w.j av a2 s . c om*/ public CliTool.ExitStatus execute(Settings settings, Environment env) { executed.set(true); return CliTool.ExitStatus.USAGE; } }; SingleCmdTool tool = new SingleCmdTool("tool", terminal, cmd); int status = tool.execute(); assertStatus(status, CliTool.ExitStatus.USAGE); assertCommandHasBeenExecuted(executed); }
From source file:org.elasticsearch.common.cli.CliToolTests.java
@Test public void testMultipleLaunch() throws Exception { Terminal terminal = new MockTerminal(); final AtomicReference<Boolean> executed = new AtomicReference<>(false); final NamedCommand cmd = new NamedCommand("cmd", terminal) { @Override//from w ww. java 2s . c o m public CliTool.ExitStatus execute(Settings settings, Environment env) { executed.set(true); return CliTool.ExitStatus.OK; } }; SingleCmdTool tool = new SingleCmdTool("tool", terminal, cmd); tool.parse("cmd", Strings.splitStringByCommaToArray("--verbose")); tool.parse("cmd", Strings.splitStringByCommaToArray("--silent")); tool.parse("cmd", Strings.splitStringByCommaToArray("--help")); }
From source file:com.jeremydyer.nifi.processors.google.GoogleSpeechProcessor.java
@Override public void onTrigger(final ProcessContext context, final ProcessSession session) throws ProcessException { FlowFile flowFile = session.get();// ww w .j a va 2 s .c o m if (flowFile == null) { return; } try { AtomicReference<String> image = new AtomicReference<>(); session.read(flowFile, new InputStreamCallback() { @Override public void process(InputStream inputStream) throws IOException { byte[] bytes = IOUtils.toByteArray(inputStream); byte[] encImage = Base64.getEncoder().encode(bytes); image.set(new String(encImage)); } }); AnnotateImageRequest request = new AnnotateImageRequest() .setImage(new Image().setContent(new String(image.get()))).setFeatures(ImmutableList .of(new Feature().setType("LANDMARK_DETECTION").setMaxResults(MAX_RESULTS))); Vision.Images.Annotate annotate = vision.images() .annotate(new BatchAnnotateImagesRequest().setRequests(ImmutableList.of(request))); BatchAnnotateImagesResponse batchResponse = annotate.execute(); assert batchResponse.getResponses().size() == 1; AnnotateImageResponse response = batchResponse.getResponses().get(0); if (response.getLandmarkAnnotations() == null) { throw new IOException(response.getError() != null ? response.getError().getMessage() : "Unknown error getting image annotations"); } StringBuilder lndMarks = new StringBuilder(); List<EntityAnnotation> landmarks = response.getLandmarkAnnotations(); System.out.printf("Found %d landmark%s\n", landmarks.size(), landmarks.size() == 1 ? "" : "s"); for (EntityAnnotation annotation : landmarks) { System.out.printf("\t%s\n", annotation.getDescription()); lndMarks.append(annotation.getDescription()); lndMarks.append(", "); } flowFile = session.putAttribute(flowFile, "landmarks", lndMarks.toString()); session.transfer(flowFile, REL_SUCCESS); } catch (Exception ex) { ex.printStackTrace(); } }
From source file:com.jayway.restassured.module.mockmvc.ContentTypeTest.java
@Test public void doesnt_add_default_charset_to_content_type_if_charset_is_defined_explicitly() { final AtomicReference<String> contentType = new AtomicReference<String>(); given().standaloneSetup(new GreetingController()).contentType(ContentType.JSON.withCharset("UTF-16")) .interceptor(new MockHttpServletRequestBuilderInterceptor() { public void intercept(MockHttpServletRequestBuilder requestBuilder) { MultiValueMap<String, Object> headers = Whitebox.getInternalState(requestBuilder, "headers"); contentType.set(String.valueOf(headers.getFirst("Content-Type"))); }//w w w .j ava 2s .c o m }).when().get("/greeting?name={name}", "Johan").then().statusCode(200); assertThat(contentType.get()).isEqualTo("application/json;charset=UTF-16"); }
From source file:org.ldp4j.server.IntegrationTestHelper.java
public String httpRequest(final HttpUriRequest request) throws Exception { final AtomicReference<String> body = new AtomicReference<String>(); ResponseHandler<String> responseHandler = new ResponseHandler<String>() { public String handleResponse(final HttpResponse response) throws ClientProtocolException, IOException { String responseBody = logResponse(response); // TODO: Add validation mechanism here body.set(responseBody); return responseBody; }//from www.j a va2s . co m private final String NL = System.getProperty("line.separator"); private String logResponse(final HttpResponse response) throws IOException { HttpEntity entity = response.getEntity(); String responseBody = entity != null ? EntityUtils.toString(entity) : null; if (logger.isDebugEnabled()) { StringBuilder builder = new StringBuilder(); builder.append("-- REQUEST COMPLETED -------------------------").append(NL); builder.append("-- RESPONSE INIT -----------------------------").append(NL); builder.append(response.getStatusLine().toString()).append(NL); builder.append("-- RESPONSE HEADERS---------------------------").append(NL); for (org.apache.http.Header h : response.getAllHeaders()) { builder.append(h.getName() + " : " + h.getValue()).append(NL); } if (responseBody != null && responseBody.length() > 0) { builder.append("-- RESPONSE BODY -----------------------------").append(NL); builder.append(responseBody).append(NL); } builder.append("-- RESPONSE END ------------------------------"); logger.debug(builder.toString()); } return responseBody; } }; logger.debug("-- REQUEST INIT -------------------------------"); logger.debug(request.getRequestLine().toString()); httpclient.execute(request, responseHandler); return body.get(); }
From source file:org.elasticsearch.common.cli.CliToolTests.java
@Test public void testIOError() throws Exception { Terminal terminal = new MockTerminal(); final AtomicReference<Boolean> executed = new AtomicReference<>(false); final NamedCommand cmd = new NamedCommand("cmd", terminal) { @Override//from w w w.j av a2s . c o m public CliTool.ExitStatus execute(Settings settings, Environment env) throws Exception { executed.set(true); throw new IOException("io error"); } }; SingleCmdTool tool = new SingleCmdTool("tool", terminal, cmd); int status = tool.execute(); assertStatus(status, CliTool.ExitStatus.IO_ERROR); assertCommandHasBeenExecuted(executed); }
From source file:org.elasticsearch.common.cli.CliToolTests.java
@Test public void testCodeError() throws Exception { Terminal terminal = new MockTerminal(); final AtomicReference<Boolean> executed = new AtomicReference<>(false); final NamedCommand cmd = new NamedCommand("cmd", terminal) { @Override//from w w w .ja va 2 s . c o m public CliTool.ExitStatus execute(Settings settings, Environment env) throws Exception { executed.set(true); throw new Exception("random error"); } }; SingleCmdTool tool = new SingleCmdTool("tool", terminal, cmd); int status = tool.execute(); assertStatus(status, CliTool.ExitStatus.CODE_ERROR); assertCommandHasBeenExecuted(executed); }
From source file:org.elasticsearch.common.cli.CliToolTests.java
@Test public void testSingleCommand_ToolHelp() throws Exception { CaptureOutputTerminal terminal = new CaptureOutputTerminal(); final AtomicReference<Boolean> executed = new AtomicReference<>(false); final NamedCommand cmd = new NamedCommand("cmd1", terminal) { @Override//from w ww .j a va 2 s .co m public CliTool.ExitStatus execute(Settings settings, Environment env) throws Exception { executed.set(true); throw new IOException("io error"); } }; SingleCmdTool tool = new SingleCmdTool("tool", terminal, cmd); int status = tool.execute(args("-h")); assertStatus(status, CliTool.ExitStatus.OK); assertThat(terminal.getTerminalOutput(), hasSize(3)); assertThat(terminal.getTerminalOutput(), hasItem(containsString("cmd1 help"))); }
From source file:com.microsoft.gittf.client.clc.commands.framework.Command.java
protected TFSTeamProjectCollection getConnection(final URI serverURI, final Repository repository) throws Exception { if (connection == null) { AtomicReference<Credentials> credentials = new AtomicReference<Credentials>(); credentials.set(getCredentials(repository)); connection = getConnection(serverURI, credentials); userCredentials = credentials.get(); }//from w ww .ja v a 2 s.c o m return connection; }