List of usage examples for java.util.concurrent.atomic AtomicReference get
public final V get()
From source file:com.kixeye.janus.client.http.rest.DefaultRestHttpClientTest.java
@Test public void postParamListTest() throws Exception { Janus janus = new Janus(VIP_TEST, new ConstServerList(VIP_TEST, "http://localhost:" + server1Port), new RandomLoadBalancer(), new ServerStatsFactory(ServerStats.class, new MetricRegistry())); DefaultRestHttpClient client = new DefaultRestHttpClient(janus, 0, DefaultRestHttpClient.UTF8_STRING_SER_DE, "text/plain"); final AtomicReference<String> requestMethod = new AtomicReference<>(null); final AtomicReference<String> requestPath = new AtomicReference<>(null); testContainer = new Container() { public void handle(Request req, Response resp) { requestMethod.set(req.getMethod()); requestPath.set(req.getTarget()); try { resp.getByteChannel().write(ByteBuffer.wrap(IOUtils.toByteArray(req.getInputStream()))); } catch (IOException e) { logger.error("Unable to write to channel."); }/*from w w w. ja v a 2 s . c om*/ } }; String result = client.post("/test_params/{}", "body", String.class, "goofy").getBody().deserialize(); Assert.assertEquals("body", result); Assert.assertEquals("POST", requestMethod.get()); Assert.assertEquals("/test_params/goofy", requestPath.get()); }
From source file:com.microsoft.tfs.client.common.ui.teambuild.commands.CheckBuildFileExistsCommand.java
private IStatus checkGitVC(final IProgressMonitor progressMonitor, final String itemPath) { try {/* w ww.ja v a2 s .c om*/ final AtomicReference<String> projectName = new AtomicReference<String>(); final AtomicReference<String> repositoryName = new AtomicReference<String>(); final AtomicReference<String> branchName = new AtomicReference<String>(); final AtomicReference<String> path = new AtomicReference<String>(); if (!GitProperties.parseGitItemUrl(itemPath, projectName, repositoryName, branchName, path)) { final String messageFormat = Messages .getString("CheckBuildFileExistsCommand.WrongBuildPojectUriErrorFormat"); //$NON-NLS-1$ final String message = MessageFormat.format(messageFormat, itemPath); return new Status(IStatus.ERROR, TFSTeamBuildPlugin.PLUGIN_ID, Status.OK, message, new BuildException(message)); } final ICommandExecutor commandExecutor = new CommandExecutor(); final QueryGitItemsCommand test = new QueryGitItemsCommand(versionControl, projectName.get(), repositoryName.get(), branchName.get(), path.get()); final IStatus status = commandExecutor.execute(test); buildFileExists = status.isOK() && test.getRepositoryItems().size() > 0; } catch (final Exception e) { // encountered a version control exception (i.e. file does not // exist). Ignore it // but log just in case it was something else. buildFileExists = false; log.warn("Ignoring exception when checking for TFSBuild.proj in " + folderPath); //$NON-NLS-1$ } return Status.OK_STATUS; }
From source file:com.netflix.curator.framework.recipes.queue.TestDistributedQueue.java
@Test public void testErrorMode() throws Exception { Timing timing = new Timing(); CuratorFramework client = CuratorFrameworkFactory.newClient(server.getConnectString(), timing.session(), timing.connection(), new RetryOneTime(1)); client.start();//from w ww . j ava 2 s .c o m try { final AtomicReference<CountDownLatch> latch = new AtomicReference<CountDownLatch>( new CountDownLatch(1)); final AtomicInteger count = new AtomicInteger(0); QueueConsumer<TestQueueItem> consumer = new QueueConsumer<TestQueueItem>() { @Override public void consumeMessage(TestQueueItem message) throws Exception { if (count.incrementAndGet() < 2) { throw new Exception(); } latch.get().countDown(); } @Override public void stateChanged(CuratorFramework client, ConnectionState newState) { } }; DistributedQueue<TestQueueItem> queue = QueueBuilder.builder(client, consumer, serializer, QUEUE_PATH) .lockPath("/locks").buildQueue(); try { queue.start(); TestQueueItem item = new TestQueueItem("1"); queue.put(item); Assert.assertTrue(timing.awaitLatch(latch.get())); Assert.assertEquals(count.get(), 2); queue.setErrorMode(ErrorMode.DELETE); count.set(0); latch.set(new CountDownLatch(1)); item = new TestQueueItem("1"); queue.put(item); Assert.assertFalse(latch.get().await(5, TimeUnit.SECONDS)); // consumer should get called only once Assert.assertEquals(count.get(), 1); } finally { queue.close(); } } finally { client.close(); } }
From source file:io.restassured.itest.java.FilterITest.java
@Test public void content_type_in_filter_doesnt_contain_charset_if_configured_not_to() { final AtomicReference<String> contentType = new AtomicReference<String>(); given().config(RestAssuredConfig.config() .encoderConfig(encoderConfig().appendDefaultContentCharsetToContentTypeIfUndefined(false))) .filter(new Filter() { public Response filter(FilterableRequestSpecification requestSpec, FilterableResponseSpecification responseSpec, FilterContext ctx) { contentType.set(requestSpec.getContentType()); return ctx.next(requestSpec, responseSpec); }//w w w .j a v a2s . c o m }).formParam("firstName", "John").formParam("lastName", "Doe").when().post("/greet").then() .statusCode(200); assertThat(contentType.get(), equalTo("application/x-www-form-urlencoded")); }
From source file:com.nokia.dempsy.mpcluster.zookeeper.ZookeeperSession.java
@Override public void stop() { AtomicReference<ZooKeeper> curZk; synchronized (this) { isRunning = false;/*from www.j av a 2 s.c om*/ curZk = zkref; zkref = null; // this blows up any more usage } Set<ZookeeperCluster> tmp = new HashSet<ZookeeperCluster>(); synchronized (cachedClusters) { tmp.addAll(cachedClusters.values()); } // stop all of the ZookeeperClusters first for (ZookeeperCluster cluster : tmp) cluster.stop(); try { curZk.get().close(); } catch (Throwable th) { /* let it go otherwise */ } }
From source file:de.sainth.recipe.backend.db.repositories.UserRepository.java
public User save(User user) { AtomicReference<User> u = new AtomicReference<>(); create.transaction(configuration -> { Long id = using(configuration).select(USERS.ID).from(USERS).where(USERS.NAME.eq(user.getUsername())) .forUpdate().fetchOneInto(Long.class); UsersRecord record;//from ww w . j ava 2s . com if (id == null) { String encrypted = ScryptPasswordEncoder.sEncode(user.getPassword()); record = using(configuration) .insertInto(USERS, USERS.NAME, USERS.EMAIL, USERS.PASSWORD, USERS.PERMISSION) .values(user.getUsername(), user.getEmail(), encrypted, user.getPermission()).returning() .fetchOne(); } else { record = using(configuration).update(USERS).set(USERS.EMAIL, user.getEmail()) .set(USERS.PERMISSION, user.getPermission()).where(USERS.ID.eq(id)).returning().fetchOne(); } u.set(new User(record.getId(), record.getName(), record.getEmail(), record.getPermission())); }); return u.get(); }
From source file:com.netflix.iep.http.RxHttpTest.java
@Test public void readTimeout() throws Exception { //set(client + ".niws.client.ReadTimeout", "100"); int code = 200; statusCode.set(code);/*from w w w. java 2 s. c o m*/ AtomicIntegerArray expected = copy(statusCounts); expected.addAndGet(code, 3); final CountDownLatch latch = new CountDownLatch(1); final AtomicReference<Throwable> throwable = new AtomicReference<>(); rxHttp.get(uri("/readTimeout")).subscribe(Actions.empty(), new Action1<Throwable>() { @Override public void call(Throwable t) { throwable.set(t); latch.countDown(); } }, new Action0() { @Override public void call() { latch.countDown(); } }); latch.await(); Assert.assertTrue(throwable.get() instanceof ReadTimeoutException); assertEquals(expected, statusCounts); }
From source file:com.netflix.iep.http.RxHttpTest.java
@Test public void readTimeoutDoesntRetry() throws Exception { //set(client + ".niws.client.ReadTimeout", "100"); set(client + ".niws.client.RetryReadTimeouts", "false"); int code = 200; statusCode.set(code);/* www . j a v a2 s . co m*/ AtomicIntegerArray expected = copy(statusCounts); expected.addAndGet(code, 1); final CountDownLatch latch = new CountDownLatch(1); final AtomicReference<Throwable> throwable = new AtomicReference<>(); rxHttp.get(uri("/readTimeout")).subscribe(Actions.empty(), new Action1<Throwable>() { @Override public void call(Throwable t) { throwable.set(t); latch.countDown(); } }, new Action0() { @Override public void call() { latch.countDown(); } }); latch.await(); Assert.assertTrue(throwable.get() instanceof ReadTimeoutException); assertEquals(expected, statusCounts); }
From source file:com.netflix.iep.http.RxHttpTest.java
@Test public void absoluteRedirect() throws Exception { int code = 200; statusCode.set(code);//from w w w . j a v a 2 s .co m redirects.set(2); AtomicIntegerArray expected = copy(statusCounts); expected.incrementAndGet(code); expected.addAndGet(302, 3); final CountDownLatch latch = new CountDownLatch(1); final AtomicReference<Throwable> throwable = new AtomicReference<>(); rxHttp.get(uri("/absoluteRedirect")).subscribe(Actions.empty(), new Action1<Throwable>() { @Override public void call(Throwable t) { throwable.set(t); latch.countDown(); } }, new Action0() { @Override public void call() { latch.countDown(); } }); latch.await(); Assert.assertNull(throwable.get()); assertEquals(expected, statusCounts); }