当前位置: 首页>>代码示例>>Java>>正文


Java AtomicReference.set方法代码示例

本文整理汇总了Java中java.util.concurrent.atomic.AtomicReference.set方法的典型用法代码示例。如果您正苦于以下问题:Java AtomicReference.set方法的具体用法?Java AtomicReference.set怎么用?Java AtomicReference.set使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.util.concurrent.atomic.AtomicReference的用法示例。


在下文中一共展示了AtomicReference.set方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: headWithEscapedMappedQueryParams

import java.util.concurrent.atomic.AtomicReference; //导入方法依赖的package包/类
/**
 * Verify HEAD with escaped query parameters
 *
 * @throws Exception
 */
@Test
public void headWithEscapedMappedQueryParams() throws Exception {
  Map<String, String> inputParams = new HashMap<String, String>();
  inputParams.put("name", "us er");
  inputParams.put("number", "100");
  final Map<String, String> outputParams = new HashMap<String, String>();
  final AtomicReference<String> method = new AtomicReference<String>();
  handler = new RequestHandler() {

    @Override
    public void handle(Request request, HttpServletResponse response) {
      method.set(request.getMethod());
      outputParams.put("name", request.getParameter("name"));
      outputParams.put("number", request.getParameter("number"));
      response.setStatus(HTTP_OK);
    }
  };
  HttpRequest request = head(url, inputParams, true);
  assertTrue(request.ok());
  assertEquals("HEAD", method.get());
  assertEquals("us er", outputParams.get("name"));
  assertEquals("100", outputParams.get("number"));
}
 
开发者ID:junicorn,项目名称:NiuBi,代码行数:29,代码来源:HttpRequestTest.java

示例2: uploadProgressSend

import java.util.concurrent.atomic.AtomicReference; //导入方法依赖的package包/类
/**
 * Verify progress callback when sending a file
 *
 * @throws Exception
 */
@Test
public void uploadProgressSend() throws Exception {
  final AtomicReference<String> body = new AtomicReference<String>();
  handler = new RequestHandler() {

    @Override
    public void handle(Request request, HttpServletResponse response) {
      body.set(new String(read()));
      response.setStatus(HTTP_OK);
    }
  };
  final File file = File.createTempFile("post", ".txt");
  new FileWriter(file).append("hello").close();

  final AtomicLong tx = new AtomicLong(0);
  UploadProgress progress = new UploadProgress() {
    public void onUpload(long transferred, long total) {
      assertEquals(file.length(), total);
      assertEquals(tx.incrementAndGet(), transferred);
    }
  };
  post(url).bufferSize(1).progress(progress).send(file).code();
  assertEquals(file.length(), tx.get());
}
 
开发者ID:junicorn,项目名称:NiuBi,代码行数:30,代码来源:HttpRequestTest.java

示例3: getInterrupted

import java.util.concurrent.atomic.AtomicReference; //导入方法依赖的package包/类
@Test
public void getInterrupted() throws CheckedFutureException, InterruptedException {
  AtomicReference<Throwable> cause = new AtomicReference<>();
  Thread t = new Thread() {
    @Override
    public void run() {
      try {
        noFuture.get(Duration.ofMinutes(1));
      } catch (CheckedFutureException e) {
        cause.set(e.getCause());
      }
    }
  };
  t.start();
  t.interrupt();
  t.join();
  assertTrue(cause.get() instanceof InterruptedException);
}
 
开发者ID:traneio,项目名称:future,代码行数:19,代码来源:NoFutureTest.java

示例4: OBSERVER_SUCCESS

import java.util.concurrent.atomic.AtomicReference; //导入方法依赖的package包/类
private static Subscriber<String> OBSERVER_SUCCESS(final AtomicReference<Throwable> onError) {
    return new DefaultSubscriber<String>() {

        @Override
        public void onComplete() {

        }

        @Override
        public void onError(Throwable e) {
            onError.set(e);
        }

        @Override
        public void onNext(String args) {

        }
    };

}
 
开发者ID:akarnokd,项目名称:RxJava3-preview,代码行数:21,代码来源:SafeSubscriberTest.java

示例5: getWithMappedQueryParams

import java.util.concurrent.atomic.AtomicReference; //导入方法依赖的package包/类
/**
 * Verify GET with query parameters
 *
 * @throws Exception
 */
@Test
public void getWithMappedQueryParams() throws Exception {
  Map<String, String> inputParams = new HashMap<String, String>();
  inputParams.put("name", "user");
  inputParams.put("number", "100");
  final Map<String, String> outputParams = new HashMap<String, String>();
  final AtomicReference<String> method = new AtomicReference<String>();
  handler = new RequestHandler() {

    @Override
    public void handle(Request request, HttpServletResponse response) {
      method.set(request.getMethod());
      outputParams.put("name", request.getParameter("name"));
      outputParams.put("number", request.getParameter("number"));
      response.setStatus(HTTP_OK);
    }
  };
  HttpRequest request = get(url, inputParams, false);
  assertTrue(request.ok());
  assertEquals("GET", method.get());
  assertEquals("user", outputParams.get("name"));
  assertEquals("100", outputParams.get("number"));
}
 
开发者ID:junicorn,项目名称:NiuBi,代码行数:29,代码来源:HttpRequestTest.java

示例6: testAwaitTerminated_FailedService

import java.util.concurrent.atomic.AtomicReference; //导入方法依赖的package包/类
public void testAwaitTerminated_FailedService() throws Exception {
  final ManualSwitchedService service = new ManualSwitchedService();
  final AtomicReference<Throwable> exception = Atomics.newReference();
  Thread waiter = new Thread() {
    @Override public void run() {
      try {
        service.awaitTerminated();
        fail("Expected an IllegalStateException");
      } catch (Throwable t) {
        exception.set(t);
      }
    }
  };
  waiter.start();
  service.startAsync();
  service.notifyStarted();
  assertEquals(State.RUNNING, service.state());
  service.notifyFailed(EXCEPTION);
  assertEquals(State.FAILED, service.state());
  waiter.join(LONG_TIMEOUT_MILLIS);
  assertFalse(waiter.isAlive());
  assertThat(exception.get()).isInstanceOf(IllegalStateException.class);
  assertEquals(EXCEPTION, exception.get().getCause());
}
 
开发者ID:zugzug90,项目名称:guava-mock,代码行数:25,代码来源:AbstractServiceTest.java

示例7: headWithMappedQueryParams

import java.util.concurrent.atomic.AtomicReference; //导入方法依赖的package包/类
/**
 * Verify HEAD with query parameters
 *
 * @throws Exception
 */
@Test
public void headWithMappedQueryParams() throws Exception {
  Map<String, String> inputParams = new HashMap<String, String>();
  inputParams.put("name", "user");
  inputParams.put("number", "100");
  final Map<String, String> outputParams = new HashMap<String, String>();
  final AtomicReference<String> method = new AtomicReference<String>();
  handler = new RequestHandler() {

    @Override
    public void handle(Request request, HttpServletResponse response) {
      method.set(request.getMethod());
      outputParams.put("name", request.getParameter("name"));
      outputParams.put("number", request.getParameter("number"));
      response.setStatus(HTTP_OK);
    }
  };
  HttpRequest request = head(url, inputParams, false);
  assertTrue(request.ok());
  assertEquals("HEAD", method.get());
  assertEquals("user", outputParams.get("name"));
  assertEquals("100", outputParams.get("number"));
}
 
开发者ID:junicorn,项目名称:NiuBi,代码行数:29,代码来源:HttpRequestTest.java

示例8: getWithVarargsQueryParams

import java.util.concurrent.atomic.AtomicReference; //导入方法依赖的package包/类
/**
 * Verify GET with query parameters
 *
 * @throws Exception
 */
@Test
public void getWithVarargsQueryParams() throws Exception {
  final Map<String, String> outputParams = new HashMap<String, String>();
  final AtomicReference<String> method = new AtomicReference<String>();
  handler = new RequestHandler() {

    @Override
    public void handle(Request request, HttpServletResponse response) {
      method.set(request.getMethod());
      outputParams.put("name", request.getParameter("name"));
      outputParams.put("number", request.getParameter("number"));
      response.setStatus(HTTP_OK);
    }
  };
  HttpRequest request = get(url, false, "name", "user", "number", "100");
  assertTrue(request.ok());
  assertEquals("GET", method.get());
  assertEquals("user", outputParams.get("name"));
  assertEquals("100", outputParams.get("number"));
}
 
开发者ID:junicorn,项目名称:NiuBi,代码行数:26,代码来源:HttpRequestTest.java

示例9: putWithMappedQueryParams

import java.util.concurrent.atomic.AtomicReference; //导入方法依赖的package包/类
/**
 * Verify PUT with query parameters
 *
 * @throws Exception
 */
@Test
public void putWithMappedQueryParams() throws Exception {
  Map<String, String> inputParams = new HashMap<String, String>();
  inputParams.put("name", "user");
  inputParams.put("number", "100");
  final Map<String, String> outputParams = new HashMap<String, String>();
  final AtomicReference<String> method = new AtomicReference<String>();
  handler = new RequestHandler() {

    @Override
    public void handle(Request request, HttpServletResponse response) {
      method.set(request.getMethod());
      outputParams.put("name", request.getParameter("name"));
      outputParams.put("number", request.getParameter("number"));
      response.setStatus(HTTP_OK);
    }
  };
  HttpRequest request = put(url, inputParams, false);
  assertTrue(request.ok());
  assertEquals("PUT", method.get());
  assertEquals("user", outputParams.get("name"));
  assertEquals("100", outputParams.get("number"));
}
 
开发者ID:junicorn,项目名称:NiuBi,代码行数:29,代码来源:HttpRequestTest.java

示例10: testSkipPhase

import java.util.concurrent.atomic.AtomicReference; //导入方法依赖的package包/类
public void testSkipPhase() throws IOException {
    MockSearchPhaseContext mockSearchPhaseContext = new MockSearchPhaseContext(1);
    mockSearchPhaseContext.searchTransport = new SearchTransportService(
        Settings.builder().put("search.remote.connect", false).build(), null, null) {

        @Override
        void sendExecuteMultiSearch(MultiSearchRequest request, SearchTask task, ActionListener<MultiSearchResponse> listener) {
          fail("no collapsing here");
        }
    };

    SearchHits hits = new SearchHits(new SearchHit[]{new SearchHit(1, "ID", new Text("type"),
        Collections.singletonMap("someField", new SearchHitField("someField", Collections.singletonList(null)))),
        new SearchHit(2, "ID2", new Text("type"),
            Collections.singletonMap("someField", new SearchHitField("someField", Collections.singletonList(null))))}, 1, 1.0F);
    InternalSearchResponse internalSearchResponse = new InternalSearchResponse(hits, null, null, null, false, null, 1);
    SearchResponse response = mockSearchPhaseContext.buildSearchResponse(internalSearchResponse, null);
    AtomicReference<SearchResponse> reference = new AtomicReference<>();
    ExpandSearchPhase phase = new ExpandSearchPhase(mockSearchPhaseContext, response, r ->
        new SearchPhase("test") {
            @Override
            public void run() throws IOException {
                reference.set(r);
            }
        }
    );
    phase.run();
    mockSearchPhaseContext.assertNoFailure();
    assertNotNull(reference.get());
    assertEquals(1, mockSearchPhaseContext.phasesExecuted.get());
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:32,代码来源:ExpandSearchPhaseTests.java

示例11: findConf

import java.util.concurrent.atomic.AtomicReference; //导入方法依赖的package包/类
private static File findConf(AtomicReference<File> parent, List<? super File> clusters) {
    String nbdirs = System.getProperty("netbeans.dirs");
    if (nbdirs != null) {
    StringTokenizer tok = new StringTokenizer(nbdirs, File.pathSeparator); // NOI18N
    while (tok.hasMoreElements()) {
        File cluster = new File(tok.nextToken());
        clusters.add(cluster);
        if (!cluster.exists()) {
            continue;
        }
        
        
        
        if (parent.get() == null) {
            parent.set(cluster.getParentFile());
        }
        
        if (!parent.get().equals(cluster.getParentFile())) {
            // we can handle only case when all clusters are in
            // the same directory these days
            return null;
        }
    }
    }
    
    return new File(new File(parent.get(), "etc"), "netbeans.clusters");
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:28,代码来源:NetBeansClusterCreator.java

示例12: testOnNextErrorAcrossThread

import java.util.concurrent.atomic.AtomicReference; //导入方法依赖的package包/类
/**
 * Test that an error from a user provided Observer.onNext is handled and emitted to the onError
 * even when done across thread boundaries with observeOn
 * @throws InterruptedException if the test is interrupted
 */
@Test
public void testOnNextErrorAcrossThread() throws InterruptedException {
    final CountDownLatch latch = new CountDownLatch(1);
    final AtomicReference<Throwable> caughtError = new AtomicReference<Throwable>();
    Flowable<Long> o = Flowable.interval(50, TimeUnit.MILLISECONDS);
    Subscriber<Long> observer = new DefaultSubscriber<Long>() {

        @Override
        public void onComplete() {
            System.out.println("completed");
            latch.countDown();
        }

        @Override
        public void onError(Throwable e) {
            System.out.println("error: " + e);
            caughtError.set(e);
            latch.countDown();
        }

        @Override
        public void onNext(Long args) {
            throw new RuntimeException("forced failure");
        }
    };
    o.observeOn(Schedulers.newThread())
    .safeSubscribe(observer);

    latch.await(2000, TimeUnit.MILLISECONDS);
    assertNotNull(caughtError.get());
}
 
开发者ID:akarnokd,项目名称:RxJava3-preview,代码行数:37,代码来源:FlowableErrorHandlingTests.java

示例13: testGetPlainSet

import java.util.concurrent.atomic.AtomicReference; //导入方法依赖的package包/类
/**
 * getPlain returns the last value set
 */
public void testGetPlainSet() {
    AtomicReference<Integer> ai = new AtomicReference<>(one);
    assertEquals(one, ai.getPlain());
    ai.set(two);
    assertEquals(two, ai.getPlain());
    ai.set(m3);
    assertEquals(m3, ai.getPlain());
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:12,代码来源:AtomicReference9Test.java

示例14: testResumeNextWithAsyncExecution

import java.util.concurrent.atomic.AtomicReference; //导入方法依赖的package包/类
@Test
public void testResumeNextWithAsyncExecution() {
    final AtomicReference<Throwable> receivedException = new AtomicReference<Throwable>();
    Disposable s = mock(Disposable.class);
    TestObservable w = new TestObservable(s, "one");
    Function<Throwable, Observable<String>> resume = new Function<Throwable, Observable<String>>() {

        @Override
        public Observable<String> apply(Throwable t1) {
            receivedException.set(t1);
            return Observable.just("twoResume", "threeResume");
        }

    };
    Observable<String> o = Observable.unsafeCreate(w).onErrorResumeNext(resume);

    Observer<String> observer = TestHelper.mockObserver();

    o.subscribe(observer);

    try {
        w.t.join();
    } catch (InterruptedException e) {
        fail(e.getMessage());
    }

    verify(observer, Mockito.never()).onError(any(Throwable.class));
    verify(observer, times(1)).onComplete();
    verify(observer, times(1)).onNext("one");
    verify(observer, Mockito.never()).onNext("two");
    verify(observer, Mockito.never()).onNext("three");
    verify(observer, times(1)).onNext("twoResume");
    verify(observer, times(1)).onNext("threeResume");
    assertNotNull(receivedException.get());
}
 
开发者ID:akarnokd,项目名称:RxJava3-preview,代码行数:36,代码来源:ObservableOnErrorResumeNextViaFunctionTest.java

示例15: testGetIfPresent

import java.util.concurrent.atomic.AtomicReference; //导入方法依赖的package包/类
public void testGetIfPresent() {
  final AtomicReference<Object> valueRef = new AtomicReference<Object>();
  Cache<Object, Object> cache = new AbstractCache<Object, Object>() {
    @Override
    public Object getIfPresent(Object key) {
      return valueRef.get();
    }
  };

  assertNull(cache.getIfPresent(new Object()));

  Object newValue = new Object();
  valueRef.set(newValue);
  assertSame(newValue, cache.getIfPresent(new Object()));
}
 
开发者ID:paul-hammant,项目名称:googles-monorepo-demo,代码行数:16,代码来源:AbstractCacheTest.java


注:本文中的java.util.concurrent.atomic.AtomicReference.set方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。