Package java.util.concurrent

Examples of java.util.concurrent.ConcurrentMap


        Assert.assertEquals(0, map.size());
    }

    @SuppressWarnings("rawtypes")
    public void test_2() throws Exception {
        ConcurrentMap map = JSON.parseObject("{}", ConcurrentMap.class);
        Assert.assertEquals(0, map.size());
    }
View Full Code Here


//    if (true) return;
    try {
      Class<?> clazz = Class.forName("java.io.ObjectStreamClass$Caches");
      Field localDescsField = clazz.getDeclaredField("localDescs");
      localDescsField.setAccessible(true);
      ConcurrentMap cm = (ConcurrentMap)localDescsField.get(null);
      // TODO [serialization] a bit extreme to wipe out everything
      cm.clear();
      // For some reason clearing the reflectors damages serialization - is it not a true cache?
//      Field reflectorsField = clazz.getDeclaredField("reflectors");
//      reflectorsField.setAccessible(true);
//      cm = (ConcurrentMap)reflectorsField.get(null);
//      cm.clear();
View Full Code Here

      runIterationTest(1, new WithinThreadExecutor());
   }

   public void testCancelingTaskMultipleProcessors() {
      insertData();
      final ConcurrentMap entries = new ConcurrentHashMap();
      final AtomicBoolean stopped = new AtomicBoolean(false);

      store.process(null, new AdvancedCacheLoader.CacheLoaderTask() {
         @Override
         public void processEntry(MarshalledEntry marshalledEntry, AdvancedCacheLoader.TaskContext taskContext) throws InterruptedException {
            synchronized (entries) {
               boolean shouldStop = entries.size() == 100 && !stopped.get();
               log.info("shouldStop = " + shouldStop);
               if (shouldStop) {
                  stopped.set(true);
                  taskContext.stop();
                  return;
               }
               entries.put(marshalledEntry.getKey(), marshalledEntry.getValue());
            }
         }
      }, persistenceExecutor, true, true);

      assertTrue(stopped.get());

      assertTrue(entries.size() <= 100 + numThreads(), "got " + entries.size() + " elements, expected less than " +
            (100 + numThreads()));
      assertTrue(entries.size() >= 100);
   }
View Full Code Here

      assertTrue(entries.size() >= 100);
   }

   private void runIterationTest(int numThreads, Executor persistenceExecutor1) {
      int numEntries = insertData();
      final ConcurrentMap entries = new ConcurrentHashMap();
      final ConcurrentHashSet threads = new ConcurrentHashSet();
      final AtomicBoolean sameKeyMultipleTimes = new AtomicBoolean();

      store.process(null, new AdvancedCacheLoader.CacheLoaderTask() {
         @Override
         public void processEntry(MarshalledEntry marshalledEntry, AdvancedCacheLoader.TaskContext taskContext) throws InterruptedException {
            Object existing = entries.put(marshalledEntry.getKey(), marshalledEntry.getValue());
            threads.add(Thread.currentThread());
            if (existing != null) {
               log.warnf("Already a value present for key %s: %s", marshalledEntry.getKey(), existing);
               sameKeyMultipleTimes.set(true);
            }
         }
      }, persistenceExecutor1, true, true);

      assertFalse(sameKeyMultipleTimes.get());
      for (int i = 0; i < numEntries; i++) {
         assertEquals(entries.get(i), i, "For key" + i);
      }

      if (multipleThreads) {
         assertEquals(threads.size(), numThreads);
      }
View Full Code Here

   private Map<Address, TEST_PING> registerInDiscoveries() {
      DiscoveryKey key = new DiscoveryKey(testName, group_addr);
      ConcurrentMap<Address, TEST_PING> discoveries = all.get(key);
      if (discoveries == null) {
         discoveries = new ConcurrentHashMap<Address, TEST_PING>();
         ConcurrentMap ret = all.putIfAbsent(key, discoveries);
         if (ret != null)
            discoveries = ret;
      }
      boolean traceEnabled = log.isTraceEnabled();
      if (traceEnabled)
View Full Code Here

  private void readObject(ObjectInputStream paramObjectInputStream)
    throws IOException, ClassNotFoundException
  {
    paramObjectInputStream.defaultReadObject();
    ConcurrentMap localConcurrentMap = (ConcurrentMap)paramObjectInputStream.readObject();
    FieldSettersHolder.COUNT_MAP_FIELD_SETTER.set(this, localConcurrentMap);
  }
View Full Code Here

@Beta
public final class Interners
{
  public static Interner newStrongInterner()
  {
    ConcurrentMap localConcurrentMap = new MapMaker().makeMap();
    return new Interner()
    {
      public Object intern(Object paramAnonymousObject)
      {
        Object localObject = this.val$map.putIfAbsent(Preconditions.checkNotNull(paramAnonymousObject), paramAnonymousObject);
View Full Code Here

    @Test
    public void parInsert() throws InterruptedException {

        ExecutorService s = Executors.newCachedThreadPool();
        final ConcurrentMap m = DBMaker.newMemoryDB().transactionDisable().make()
                .createTreeMap("test")
                .valueSerializer(Serializer.LONG)
                .makeLongMap();

        long t = System.currentTimeMillis();

        for(int j=0;j<threadNum;j++){
            final long core = j;
            s.submit(new Runnable() {
                @Override public void run() {
                    for(Long n=core;n<max;n+=threadNum){
                        m.put(n,n);
                    }
                }
            });


        }

        s.shutdown();
        s.awaitTermination(1000, TimeUnit.SECONDS);

        System.out.printf("  Threads %d, time %,d\n",threadNum,System.currentTimeMillis()-t);


        assertEquals(max,m.size());
    }
View Full Code Here

   * @throws SQLException
   */
  @SuppressWarnings({ "unchecked", "rawtypes" })
  @Test
  public void testStatementCacheClear() throws SecurityException, NoSuchFieldException, IllegalArgumentException, IllegalAccessException, SQLException {
    ConcurrentMap mockCache = createNiceMock(ConcurrentMap.class);
    List<StatementHandle> mockStatementCollections = createNiceMock(List.class);
    StatementCache testClass = new StatementCache(1, false, null);
    Field field = testClass.getClass().getDeclaredField("cache");
    field.setAccessible(true);
    field.set(testClass, mockCache);
   
    Iterator<StatementHandle> mockIterator = createNiceMock(Iterator.class);
    StatementHandle mockStatement = createNiceMock(StatementHandle.class);
   
    expect(mockCache.values()).andReturn(mockStatementCollections).anyTimes();
    expect(mockStatementCollections.iterator()).andReturn(mockIterator).anyTimes();
    expect(mockIterator.hasNext()).andReturn(true).times(2).andReturn(false).once();
    expect(mockIterator.next()).andReturn(mockStatement).anyTimes();
    mockStatement.close();
    expectLastCall().once().andThrow(new SQLException()).once();
   
    mockCache.clear();
    expectLastCall().once();
    replay(mockCache, mockStatementCollections, mockIterator,mockStatement);
   
    testClass.clear();
    verify(mockCache, mockStatement);
View Full Code Here

   */
  @SuppressWarnings({ "unchecked", "rawtypes" })
  @Test
  public void testStatementCacheCheckForProperClosure() throws SecurityException, NoSuchFieldException, IllegalArgumentException, IllegalAccessException, SQLException {
   
    ConcurrentMap mockCache = createNiceMock(ConcurrentMap.class);
    List<StatementHandle> mockStatementCollections = createNiceMock(List.class);
    StatementCache testClass = new StatementCache(1, false, null);
    Field field = testClass.getClass().getDeclaredField("cache");
    field.setAccessible(true);
    field.set(testClass, mockCache);

    field = testClass.getClass().getDeclaredField("logger");
    TestUtils.setFinalStatic(field, mockLogger);

    Iterator<StatementHandle> mockIterator = createNiceMock(Iterator.class);
    StatementHandle mockStatement = createNiceMock(StatementHandle.class);
   
    expect(mockCache.values()).andReturn(mockStatementCollections).anyTimes();
    expect(mockStatementCollections.iterator()).andReturn(mockIterator).anyTimes();
    expect(mockIterator.hasNext()).andReturn(true).once().andReturn(false).once();
    expect(mockIterator.next()).andReturn(mockStatement).anyTimes();
    expect(mockStatement.isClosed()).andReturn(false).once();

View Full Code Here

TOP

Related Classes of java.util.concurrent.ConcurrentMap

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.