コード例 #1
0
ファイル: ThreadContextTest.java プロジェクト: whimet/parfait
 public void testGetAfterRemoveReturnsNull() {
   final String testKey = "hefty";
   final Object testValue = new Object();
   context.put(testKey, testValue);
   context.remove(testKey);
   assertNull("remove() should result in null value for get()", context.get(testKey));
 }
コード例 #2
0
 @Test
 public void shouldRemoveAnEntryFromTheMapWhenAutoClosed() throws Exception {
   try (final CloseableThreadContext ignored = CloseableThreadContext.put(key, value)) {
     assertThat(ThreadContext.get(key), is(value));
   }
   assertThat(ThreadContext.containsKey(key), is(false));
 }
コード例 #3
0
 @Test
 public void shouldPushAndPopAnEntryToTheStack() throws Exception {
   final String message = "message";
   try (final CloseableThreadContext ignored = CloseableThreadContext.push(message)) {
     assertThat(ThreadContext.peek(), is(message));
   }
   assertThat(ThreadContext.peek(), is(""));
 }
コード例 #4
0
 @Test
 public void shouldUseAnEmptyStringIfNoValueIsSupplied() throws Exception {
   final String key2 = "key2";
   try (final CloseableThreadContext ignored = CloseableThreadContext.put(key, value, key2)) {
     assertThat(ThreadContext.get(key), is(value));
     assertThat(ThreadContext.get(key2), is(""));
   }
 }
コード例 #5
0
 @Test
 public void shouldPreserveOldEntriesFromTheMapWhenAutoClosed() throws Exception {
   final String oldValue = "oldValue";
   ThreadContext.put(key, oldValue);
   try (final CloseableThreadContext ignored = CloseableThreadContext.put(key, value)) {
     assertThat(ThreadContext.get(key), is(value));
   }
   assertThat(ThreadContext.get(key), is(oldValue));
 }
コード例 #6
0
 @Test
 public void shouldAddTwoEntriesToTheMap() throws Exception {
   final String key2 = "key2";
   final String value2 = "value2";
   try (final CloseableThreadContext ignored =
       CloseableThreadContext.put(key, value, key2, value2)) {
     assertThat(ThreadContext.get(key), is(value));
     assertThat(ThreadContext.get(key2), is(value2));
   }
 }
コード例 #7
0
 @Test
 public void shouldPushAndPopAParameterizedEntryToTheStack() throws Exception {
   final String parameterizedMessage = "message {}";
   final String parameterizedMessageParameter = "param";
   final String formattedMessage =
       parameterizedMessage.replace("{}", parameterizedMessageParameter);
   try (final CloseableThreadContext ignored =
       CloseableThreadContext.push(parameterizedMessage, parameterizedMessageParameter)) {
     assertThat(ThreadContext.peek(), is(formattedMessage));
   }
   assertThat(ThreadContext.peek(), is(""));
 }
コード例 #8
0
 @Test
 public void shouldNestEntries() throws Exception {
   final String oldValue = "oldValue";
   final String innerValue = "innerValue";
   ThreadContext.put(key, oldValue);
   try (final CloseableThreadContext ignored = CloseableThreadContext.put(key, value)) {
     assertThat(ThreadContext.get(key), is(value));
     try (final CloseableThreadContext ignored2 = CloseableThreadContext.put(key, innerValue)) {
       assertThat(ThreadContext.get(key), is(innerValue));
     }
     assertThat(ThreadContext.get(key), is(value));
   }
   assertThat(ThreadContext.get(key), is(oldValue));
 }
コード例 #9
0
ファイル: TestData.java プロジェクト: ahlfors/the_grinder
          public RecorderHolder initialValue() {
            final ThreadContext threadContext = m_threadContextLocator.get();

            if (threadContext == null) {
              throw new UncheckedException("Only Worker Threads can invoke tests");
            }

            final TestRecorder recorder =
                new TestRecorder(
                    threadContext.getDispatchResultReporter(),
                    new StopWatchImplementation(m_timeAuthority));

            return new RecorderHolder(threadContext, recorder);
          }
コード例 #10
0
ファイル: TestData.java プロジェクト: ahlfors/the_grinder
 public void end(boolean success) {
   if (--m_nestingDepth == 0) {
     // Leaving outer frame.
     m_recorder.end(success);
     m_threadContext.popDispatchContext();
   }
 }
コード例 #11
0
ファイル: TestData.java プロジェクト: ahlfors/the_grinder
 public void start() throws DispatchStateException {
   if (m_nestingDepth++ == 0) {
     // Entering outer frame.
     m_threadContext.pushDispatchContext(m_recorder);
     m_recorder.start();
   }
 }
コード例 #12
0
ファイル: TaskExecutor.java プロジェクト: thaingo/dimdwarf
 public void execute(final Runnable command) {
   ThreadContext.runInContext(
       context.get(),
       new Runnable() {
         public void run() {
           filters.get().execute(command);
         }
       });
 }
コード例 #13
0
ファイル: ThreadContextTest.java プロジェクト: whimet/parfait
  public void testClearRemovesMDCValue() {

    ThreadContext log4jThreadContext = ThreadContext.newMDCEnabledContext();

    Hashtable mdcContext = MDC.getContext();
    assertNull(mdcContext);

    final String testKey = "painter";
    log4jThreadContext.put(testKey, 7);

    mdcContext = MDC.getContext();
    assertEquals(1, mdcContext.size());

    log4jThreadContext.clear();

    assertEquals(0, mdcContext.size());

    assertNull("get() after clear should return null", log4jThreadContext.get(testKey));
  }
コード例 #14
0
ファイル: CallSiteDescriptor.java プロジェクト: usev6/nqp
  /** Create a new callframe and arg list to add an invokee argument at the front. */
  public CallSiteDescriptor injectInvokee(
      ThreadContext tc, Object[] oldArgs, SixModelObject invokee) {
    Object[] newArgs = new Object[oldArgs.length + 1];
    System.arraycopy(oldArgs, 0, newArgs, 1, oldArgs.length);
    newArgs[0] = invokee;

    byte[] newFlags = new byte[argFlags.length + 1];
    System.arraycopy(argFlags, 0, newFlags, 1, argFlags.length);
    newFlags[0] = ARG_OBJ;

    tc.flatArgs = newArgs;
    return new CallSiteDescriptor(newFlags, names);
  }
コード例 #15
0
 public void restart() {
   synchronized (lifecycleLock) {
     ThreadContext.get().setCurrentFactory(factory);
     fireLifecycleEvent(RESTARTING);
     paused.set(true);
     final Node node = factory.node;
     final ILogger logger = getLogger();
     List<Record> lsOwnedRecords = new ArrayList<Record>();
     for (CMap cmap : node.concurrentMapManager.getCMaps().values()) {
       if (cmap.isUserMap()) {
         lsOwnedRecords.addAll(cmap.getMapIndexService().getOwnedRecords());
       }
     }
     node.onRestart();
     node.clientHandlerService.restart();
     node.connectionManager.onRestart();
     node.clusterManager.onRestart();
     node.concurrentMapManager.onRestart();
     node.rejoin();
     final CountDownLatch latch = new CountDownLatch(lsOwnedRecords.size());
     final ParallelExecutor executor = node.executorManager.newParallelExecutor(16);
     for (final Record ownedRecord : lsOwnedRecords) {
       executor.execute(
           new Runnable() {
             public void run() {
               try {
                 ConcurrentMapManager.MPut mput = node.concurrentMapManager.new MPut();
                 mput.merge(ownedRecord);
                 // invalidate record now (skipped invalidation on restart)
                 ownedRecord.invalidate();
                 latch.countDown();
               } catch (Exception e) {
                 logger.log(Level.WARNING, e.getMessage(), e);
               }
             }
           });
     }
     try {
       latch.await(60, TimeUnit.SECONDS);
     } catch (InterruptedException ignored) {
     }
     paused.set(false);
     fireLifecycleEvent(RESTARTED);
   }
 }
コード例 #16
0
ファイル: ThreadContextTest.java プロジェクト: whimet/parfait
 public void testCanAccessOtherThreadsContext() throws InterruptedException {
   final String testKey = "vanity";
   final Object testValue = new Object();
   final CountDownLatch finished = new CountDownLatch(1);
   final Thread otherThread =
       new Thread(
           new Runnable() {
             public void run() {
               context.put(testKey, testValue);
               finished.countDown();
             }
           });
   otherThread.start();
   finished.await();
   Map<String, Object> forThread = context.forThread(otherThread);
   assertEquals(1, forThread.size());
   assertEquals(testValue, forThread.get(testKey));
 }
コード例 #17
0
 @Before
 public void setUp() throws Exception {
   ThreadContext.clearAll();
 }
コード例 #18
0
ファイル: ThreadContextTest.java プロジェクト: whimet/parfait
 public void testGetsEmptyContextForUnknownThread() {
   assertEquals(0, context.forThread(new Thread()).size());
 }
コード例 #19
0
ファイル: ThreadContextTest.java プロジェクト: whimet/parfait
 public void testClearRemovesValue() {
   final String testKey = "painter";
   context.put(testKey, 7);
   context.clear();
   assertNull("get() after clear should return null", context.get(testKey));
 }
コード例 #20
0
 @Test
 public void shouldAddAnEntryToTheMap() throws Exception {
   try (final CloseableThreadContext ignored = CloseableThreadContext.put(key, value)) {
     assertThat(ThreadContext.get(key), is(value));
   }
 }
コード例 #21
0
ファイル: ThreadContextTest.java プロジェクト: whimet/parfait
 public void testGetRetrievesPutValue() {
   final String testKey = "brainy";
   final Object testValue = new Object();
   context.put(testKey, testValue);
   assertEquals(testValue, context.get(testKey));
 }
コード例 #22
0
 public ExecutionScope(final String name) {
   // Add this IScope to the stack of nested IScopes.
   ThreadContext.addIScope(this, name);
 }
コード例 #23
0
 @Override
 public void close() {
   // Remove this IScope from the stack of nested IScopes.
   ThreadContext.removeIScope(this);
 }
コード例 #24
0
ファイル: ThreadContextTest.java プロジェクト: whimet/parfait
 public void testGetOfUnusedKeyReturnsNull() {
   final String testKey = "handy";
   assertNull("get() of unused key should return null", context.get(testKey));
 }