List of usage examples for java.util.concurrent.atomic AtomicReference AtomicReference
public AtomicReference()
From source file:com.jayway.restassured.module.mockmvc.ContentTypeTest.java
@Test public void adds_default_charset_to_content_type_by_default() { final AtomicReference<String> contentType = new AtomicReference<String>(); given().standaloneSetup(new GreetingController()).contentType(ContentType.JSON) .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 ww.j a v a 2s. c o m*/ }).when().get("/greeting?name={name}", "Johan").then().statusCode(200); assertThat(contentType.get()).isEqualTo("application/json;charset=" + RestAssuredMockMvcConfig.config().getEncoderConfig().defaultContentCharset()); }
From source file:com.king.platform.net.http.integration.MultiPart.java
@Test public void postMultiPart() throws Exception { AtomicReference<List<FileItem>> partReferences = new AtomicReference<>(); AtomicReference<Exception> exceptionReference = new AtomicReference<>(); integrationServer.addServlet(new HttpServlet() { @Override//from w w w .jav a 2 s .c om protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { ServletFileUpload servletFileUpload = new ServletFileUpload(new DiskFileItemFactory()); try { List<FileItem> fileItems = servletFileUpload.parseRequest(req); partReferences.set(fileItems); } catch (FileUploadException e) { exceptionReference.set(e); } } }, "/testMultiPart"); httpClient .createPost( "http://localhost:" + port + "/testMultiPart") .idleTimeoutMillis( 0) .totalRequestTimeoutMillis( 0) .content( new MultiPartBuilder() .addPart( MultiPartBuilder .create("text1", "Message 1", StandardCharsets.ISO_8859_1) .contentType("multipart/form-data")) .addPart(MultiPartBuilder.create("binary1", new byte[] { 0x00, 0x01, 0x02 }) .contentType("application/octet-stream").charset(StandardCharsets.UTF_8) .fileName("application.bin")) .addPart(MultiPartBuilder.create("text2", "Message 2", StandardCharsets.ISO_8859_1)) .build()) .build().execute().join(); assertNull(exceptionReference.get()); List<FileItem> fileItems = partReferences.get(); FileItem fileItem = fileItems.get(1); assertEquals("application/octet-stream; charset=UTF-8", fileItem.getContentType()); assertEquals("binary1", fileItem.getFieldName()); assertEquals("application.bin", fileItem.getName()); }
From source file:com.foglyn.core.FoglynCorePlugin.java
/** * The constructor/* w ww. jav a 2 s . c om*/ */ public FoglynCorePlugin() { this.connectionManager = new AtomicReference<MultiThreadedHttpConnectionManager>(); this.httpClient = new AtomicReference<HttpClient>(); this.clientFactory = new AtomicReference<FogBugzClientFactory>(null); this.proxyServiceTracker = new AtomicReference<ServiceTracker>(null); }
From source file:com.google.dart.engine.internal.index.AbstractDartTest.java
/** * @return {@link ASTNode} which has required offset and type. *///from w w w. ja va2 s.com public static <E extends ASTNode> E findNode(ASTNode root, final int offset, final Class<E> clazz) { final AtomicReference<E> resultRef = new AtomicReference<E>(); root.accept(new GeneralizingASTVisitor<Void>() { @Override @SuppressWarnings("unchecked") public Void visitNode(ASTNode node) { if (node.getOffset() <= offset && offset < node.getEnd() && clazz.isInstance(node)) { resultRef.set((E) node); } return super.visitNode(node); } }); E result = resultRef.get(); assertNotNull(result); return result; }
From source file:com.netflix.curator.framework.recipes.cache.TestNodeCache.java
@Test public void testDeleteThenCreate() throws Exception { NodeCache cache = null;/*from ww w . j a v a 2 s .c o m*/ CuratorFramework client = CuratorFrameworkFactory.newClient(server.getConnectString(), new RetryOneTime(1)); client.start(); try { client.create().creatingParentsIfNeeded().forPath("/test/foo", "one".getBytes()); final AtomicReference<Throwable> error = new AtomicReference<Throwable>(); client.getUnhandledErrorListenable().addListener(new UnhandledErrorListener() { @Override public void unhandledError(String message, Throwable e) { error.set(e); } }); final Semaphore semaphore = new Semaphore(0); cache = new NodeCache(client, "/test/foo"); cache.getListenable().addListener(new NodeCacheListener() { @Override public void nodeChanged() throws Exception { semaphore.release(); } }); cache.start(true); Assert.assertEquals(cache.getCurrentData().getData(), "one".getBytes()); client.delete().forPath("/test/foo"); Assert.assertTrue(semaphore.tryAcquire(1, 10, TimeUnit.SECONDS)); client.create().forPath("/test/foo", "two".getBytes()); Assert.assertTrue(semaphore.tryAcquire(1, 10, TimeUnit.SECONDS)); Throwable t = error.get(); if (t != null) { Assert.fail("Assert", t); } Assert.assertEquals(cache.getCurrentData().getData(), "two".getBytes()); cache.close(); } finally { IOUtils.closeQuietly(cache); IOUtils.closeQuietly(client); } }
From source file:com.raphfrk.craftproxyclient.gui.GUIManager.java
public static JSONObject getNewLoginDetails() { final AtomicReference<LoginDialog> login = new AtomicReference<LoginDialog>(); Runnable r = (new Runnable() { public void run() { login.set(new LoginDialog(CraftProxyClient.getGUI())); login.get().setVisible(true); login.get().dispose();//from w w w. j a va2s .c o m } }); if (SwingUtilities.isEventDispatchThread()) { r.run(); } else { try { SwingUtilities.invokeAndWait(r); } catch (InvocationTargetException | InterruptedException e) { return null; } } return AuthManager.authAccessToken(login.get().getEmail(), login.get().getPassword()); }
From source file:de.sainth.recipe.backend.db.repositories.BasicUnitRepository.java
public BasicUnit save(BasicUnit basicUnit) { AtomicReference<BasicUnit> bu = new AtomicReference<>(); create.transaction(configuration -> { using(configuration).insertInto(BASIC_UNITS, BASIC_UNITS.SHORTNAME, BASIC_UNITS.LONGNAME) .values(basicUnit.getShortname(), basicUnit.getLongname()).onConflict().doUpdate() .set(BASIC_UNITS.LONGNAME, basicUnit.getLongname()).execute(); bu.set(using(configuration).selectFrom(BASIC_UNITS) .where(BASIC_UNITS.SHORTNAME.eq(basicUnit.getShortname())).fetchOneInto(BasicUnit.class)); });/*from w w w . j a v a 2s . c o m*/ return bu.get(); }
From source file:de.sainth.recipe.backend.db.repositories.UnitRepository.java
public Unit save(Unit unit) { AtomicReference<Unit> bu = new AtomicReference<>(); create.transaction(configuration -> { using(configuration)/*from w ww . ja v a 2 s . co m*/ .insertInto(UNITS, UNITS.SHORTNAME, UNITS.LONGNAME, UNITS.CONVERSION_FACTOR, UNITS.BASIC_UNIT) .values(unit.getShortname(), unit.getLongname(), unit.getConversionFactor(), unit.getBasicUnit()) .onConflict().doUpdate().set(UNITS.LONGNAME, unit.getLongname()) .set(UNITS.CONVERSION_FACTOR, unit.getConversionFactor()) .set(UNITS.BASIC_UNIT, unit.getBasicUnit()).execute(); bu.set(using(configuration).selectFrom(UNITS).where(UNITS.SHORTNAME.eq(unit.getShortname())) .fetchOneInto(Unit.class)); }); return bu.get(); }
From source file:io.termd.core.telnet.TelnetHandlerTest.java
@Test public void testRejectEcho() throws Exception { final AtomicReference<Boolean> serverValue = new AtomicReference<>(); EchoOptionHandler optionHandler = new EchoOptionHandler(false, false, false, false); testOptionValue(() -> new TelnetHandler() { @Override/*from w w w . j a v a 2 s. c o m*/ protected void onOpen(TelnetConnection conn) { conn.writeWillOption(Option.ECHO); } @Override protected void onEcho(boolean echo) { serverValue.set(echo); testComplete(); } }, optionHandler); assertEquals(false, serverValue.get()); assertEquals(false, optionHandler.getAcceptRemote()); }
From source file:de.sainth.recipe.backend.db.repositories.FoodRepository.java
public Food save(Food food) { AtomicReference<Food> bu = new AtomicReference<>(); create.transaction(configuration -> { Long id = using(configuration).select(FOODS.ID).from(FOODS).where(FOODS.NAME.eq(food.getName())) .forUpdate().fetchOneInto(Long.class); FoodsRecord record;//from w w w .jav a 2s . com if (id == null) { record = using(configuration) .insertInto(FOODS, FOODS.NAME, FOODS.POINTS, FOODS.POINTS_BASE_AMOUNT, FOODS.BASIC_UNIT) .values(food.getName(), food.getPoints(), food.getPointsBaseAmount(), food.getBasicUnit()) .returning().fetchOne(); } else { record = using(configuration).update(FOODS).set(FOODS.NAME, food.getName()) .set(FOODS.POINTS, food.getPoints()) .set(FOODS.POINTS_BASE_AMOUNT, food.getPointsBaseAmount()) .set(FOODS.BASIC_UNIT, food.getBasicUnit()).where(FOODS.ID.eq(id)).returning().fetchOne(); } bu.set(new Food(record.getId(), record.getName(), record.getPoints(), record.getPointsBaseAmount(), record.getBasicUnit())); }); return bu.get(); }