java.util.concurrent.ConcurrentLinkedQueue Java Examples

The following examples show how to use java.util.concurrent.ConcurrentLinkedQueue. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ConnectedComponents.java    From codebase with GNU Lesser General Public License v3.0 6 votes vote down vote up
private void constructConnectedComponent(V v, Collection<V> toVisit) {
	IFragment<E,V> f = new Fragment<E,V>(this.g);
	Set<V> visited = new HashSet<V>();
	visited.add(v);
	Queue<V> queue = new ConcurrentLinkedQueue<V>();
	queue.add(v);
	
	while (!queue.isEmpty()) {
		V vv = queue.poll();
		f.addAll(this.g.getEdges(vv));
		
		for (V vvv : this.g.getAdjacent(vv)) {
			if (!visited.contains(vvv))
				queue.add(vvv);
			
			visited.add(vvv);
			toVisit.remove(vvv);
		}
	}
	
	this.components.add(f);
}
 
Example #2
Source File: LocalCache.java    From codebuff with BSD 2-Clause "Simplified" License 6 votes vote down vote up
Segment(
     LocalCache<K, V> map,
     int initialCapacity,
     long maxSegmentWeight,
     StatsCounter statsCounter) {
  this.map = map;
  this.maxSegmentWeight = maxSegmentWeight;
  this.statsCounter = checkNotNull(statsCounter);
  initTable(newEntryArray(initialCapacity));
  keyReferenceQueue = map.usesKeyReferences() ? new ReferenceQueue<K>() : null;
  valueReferenceQueue = map.usesValueReferences() ? new ReferenceQueue<V>() : null;
  recencyQueue =
    map.usesAccessQueue()
      ? new ConcurrentLinkedQueue<ReferenceEntry<K, V>>()
      : LocalCache.<ReferenceEntry<K, V>>discardingQueue();
  writeQueue =
    map.usesWriteQueue()
      ? new WriteQueue<K, V>()
      : LocalCache.<ReferenceEntry<K, V>>discardingQueue();
  accessQueue =
    map.usesAccessQueue()
      ? new AccessQueue<K, V>()
      : LocalCache.<ReferenceEntry<K, V>>discardingQueue();
}
 
Example #3
Source File: BackpressureChunkingTest.java    From reactive-grpc with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Test
public void chunkOperatorCorrectlyChunksInfiniteRequestFusion() {
    int chunkSize = DEFAULT_CHUNK_SIZE;

    int partOfChunk = TWO_THIRDS_OF_DEFAULT_CHUNK_SIZE;
    int num = chunkSize * 2;

    AbstractStreamObserverAndPublisher<Long> source =
            new TestStreamObserverAndPublisherWithFusion<Long>(new ConcurrentLinkedQueue<Long>(), null);
    AsyncRangeCallStreamObserver observer = new AsyncRangeCallStreamObserver(Executors.newSingleThreadExecutor(), source, num);
    source.onSubscribe(observer);
    TestSubscriber<Long> testSubscriber = Flowable.fromPublisher(source)
                                                  .observeOn(Schedulers.trampoline())
                                                  .test();


    testSubscriber.awaitTerminalEvent();
    testSubscriber.assertComplete();

    assertThat(observer.requestsQueue).containsExactly(chunkSize, partOfChunk, partOfChunk, partOfChunk);
    assertThat(source.outputFused).isTrue();
}
 
Example #4
Source File: PendiqService.java    From xDrip-plus with GNU General Public License v3.0 6 votes vote down vote up
private void expectReply(final ConcurrentLinkedQueue<QueueItem> queue, final QueueItem item) {
    final long wait_time = 3000;
    Inevitable.task("pendiq-expect-reply-" + item.description, wait_time, new Runnable() {
        @Override
        public void run() {
            if (JoH.msSince(lastProcessedIncomingData) > wait_time) {
                UserError.Log.d(TAG, "GOT NO REPLY FOR: " + item.description + " @ " + item.retries);
                item.retries++;
                if (item.retries <= MAX_QUEUE_RETRIES) {
                    UserError.Log.d(TAG, "Retrying due to no reply: " + item.description);
                    writeQueueItem(queue, item);
                }
            }
        }
    });
}
 
Example #5
Source File: CrailBenchmark.java    From crail with Apache License 2.0 6 votes vote down vote up
private void warmUp(String filename, int operations, ConcurrentLinkedQueue<CrailBuffer> bufferList) throws Exception {
	Random random = new Random();
	String warmupFilename = filename + random.nextInt();
	System.out.println("warmUp, warmupFile " + warmupFilename + ", operations " + operations);
	if (operations > 0){
		CrailFile warmupFile = fs.create(warmupFilename, CrailNodeType.DATAFILE, CrailStorageClass.DEFAULT, CrailLocationClass.DEFAULT).get().asFile();
		CrailBufferedOutputStream warmupStream = warmupFile.getBufferedOutputStream(0);
		for (int i = 0; i < operations; i++){
			CrailBuffer buf = bufferList.poll();
			buf.clear();
			warmupStream.write(buf.getByteBuffer());
			bufferList.add(buf);
		}
		warmupStream.purge().get();
		warmupStream.close();
		fs.delete(warmupFilename, false).get().syncDir();			
	}
}
 
Example #6
Source File: InstagramAbstractProvider.java    From streams with Apache License 2.0 6 votes vote down vote up
@Override
public void prepare(Object configurationObject) {
  this.dataQueue = new ConcurrentLinkedQueue<>();
  this.isCompleted = new AtomicBoolean(false);

  Objects.requireNonNull(config);
  Objects.requireNonNull(config.getOauth());
  Objects.requireNonNull(config.getOauth().getClientId());
  Objects.requireNonNull(config.getOauth().getClientSecret());
  Objects.requireNonNull(config.getOauth().getAccessToken());
  Objects.requireNonNull(config.getThreadsPerProvider());

  try {
    client = Instagram.getInstance(this.config);
  } catch (InstantiationException ex) {
    LOGGER.error("InstantiationException", ex);
  }

  Objects.requireNonNull(client);

}
 
Example #7
Source File: TestConcurrentLinkedQueue.java    From tutorials with MIT License 6 votes vote down vote up
@Test
public void givenProducerOffersElementInQueue_WhenConsumerPollsQueue_ThenItRetrievesElement() throws Exception {
    int element = 1;

    ExecutorService executorService = Executors.newFixedThreadPool(2);
    ConcurrentLinkedQueue<Integer> concurrentLinkedQueue = new ConcurrentLinkedQueue<>();
    Runnable offerTask = () -> concurrentLinkedQueue.offer(element);

    Callable<Integer> pollTask = () -> {
        while (concurrentLinkedQueue.peek() != null) {
            return concurrentLinkedQueue.poll()
                .intValue();
        }
        return null;
    };

    executorService.submit(offerTask);
    TimeUnit.SECONDS.sleep(1);

    Future<Integer> returnedElement = executorService.submit(pollTask);
    assertThat(returnedElement.get()
        .intValue(), is(equalTo(element)));
    executorService.awaitTermination(1, TimeUnit.SECONDS);
    executorService.shutdown();
}
 
Example #8
Source File: RemovePollRace.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
Collection<Queue<Boolean>> concurrentQueues() {
    List<Queue<Boolean>> queues = new ArrayList<Queue<Boolean>>();
    queues.add(new ConcurrentLinkedDeque<Boolean>());
    queues.add(new ConcurrentLinkedQueue<Boolean>());
    queues.add(new ArrayBlockingQueue<Boolean>(count, false));
    queues.add(new ArrayBlockingQueue<Boolean>(count, true));
    queues.add(new LinkedBlockingQueue<Boolean>());
    queues.add(new LinkedBlockingDeque<Boolean>());
    queues.add(new LinkedTransferQueue<Boolean>());

    // Following additional implementations are available from:
    // http://gee.cs.oswego.edu/dl/concurrency-interest/index.html
    // queues.add(new SynchronizedLinkedListQueue<Boolean>());

    // Avoid "first fast, second slow" benchmark effect.
    Collections.shuffle(queues);
    return queues;
}
 
Example #9
Source File: DefaultPojoClassLookupService.java    From openpojo with Apache License 2.0 6 votes vote down vote up
public List<PojoClass> getPojoClassesRecursively(final String packageName, final PojoClassFilter pojoClassFilter) {
  final List<PojoClass> pojoClasses = new LinkedList<PojoClass>();
  final PojoClassFilter finalFilterChain = getFinalFilterChain(pojoClassFilter);

  final PojoPackage pojoPackage = PojoPackageFactory.getPojoPackage(packageName);

  Queue<PojoPackage> pending = new ConcurrentLinkedQueue<PojoPackage>();
  pending.add(pojoPackage);

  while (!pending.isEmpty()) {
    final PojoPackage entry = pending.remove();
    pending.addAll(entry.getPojoSubPackages());
    pojoClasses.addAll(entry.getPojoClasses(finalFilterChain));
  }
  return pojoClasses;
}
 
Example #10
Source File: UpgradeDatalakeFlowEventChainFactory.java    From cloudbreak with Apache License 2.0 6 votes vote down vote up
@Override
public Queue<Selectable> createFlowTriggerEventQueue(DatalakeClusterUpgradeTriggerEvent event) {
    Queue<Selectable> chain = new ConcurrentLinkedQueue<>();

    Optional<StackStatus> stackStatusOpt = stackStatusService.findFirstByStackIdOrderByCreatedDesc(event.getResourceId());
    StackStatus unknownStackStatus = new StackStatus();
    unknownStackStatus.setDetailedStackStatus(DetailedStackStatus.UNKNOWN);
    DetailedStackStatus detailedStackStatus = stackStatusOpt.orElse(unknownStackStatus).getDetailedStackStatus();
    if (DetailedStackStatus.CLUSTER_UPGRADE_FAILED.equals(detailedStackStatus)) {
        chain.add(new DatalakeClusterUpgradeTriggerEvent(
                CLUSTER_MANAGER_UPGRADE_FINISHED_EVENT.event(), event.getResourceId(), event.accepted(), event.getTargetImage()));
    } else {
        chain.add(new DatalakeClusterUpgradeTriggerEvent(
                CLUSTER_MANAGER_UPGRADE_EVENT.event(), event.getResourceId(), event.accepted(), event.getTargetImage()));
    }

    return chain;
}
 
Example #11
Source File: YamlCollectionCreator.java    From Diorite with MIT License 6 votes vote down vote up
static void putAllCollections(Map<Class<?>, IntFunction<?>> map)
{
    safePut(map, ArrayList.class, ArrayList::new);
    safePut(map, HashSet.class, LinkedHashSet::new);
    safePut(map, Properties.class, x -> new Properties());
    safePut(map, Hashtable.class, Hashtable::new);

    safePut(map, Collection.class, ArrayList::new);
    safePut(map, Set.class, LinkedHashSet::new);
    safePut(map, List.class, ArrayList::new);
    safePut(map, SortedSet.class, x -> new TreeSet<>());
    safePut(map, Queue.class, x -> new ConcurrentLinkedQueue<>());
    safePut(map, Deque.class, x -> new ConcurrentLinkedDeque<>());
    safePut(map, BlockingQueue.class, x -> new LinkedBlockingQueue<>());
    safePut(map, BlockingDeque.class, x -> new LinkedBlockingDeque<>());


    safePut(map, HashMap.class, LinkedHashMap::new);
    safePut(map, LinkedHashMap.class, LinkedHashMap::new);
    safePut(map, ConcurrentHashMap.class, ConcurrentHashMap::new);

    safePut(map, Map.class, LinkedHashMap::new);
    safePut(map, ConcurrentMap.class, x -> new ConcurrentSkipListMap<>());
    safePut(map, ConcurrentNavigableMap.class, x -> new ConcurrentSkipListMap<>());
    safePut(map, SortedMap.class, i -> new TreeMap<>());
}
 
Example #12
Source File: MainActivity.java    From Mi365Locker with GNU General Public License v3.0 6 votes vote down vote up
private void stopScan() {
    for (Map.Entry<String, DeviceConnection> device_entry: this.devices_connections.entrySet())
    {
        device_entry.getValue().dispose();
    }
    bluetoothLeScanner.stopScan(this.mLeScanCallback);

    this.rxBleClient = RxBleClient.create(getApplicationContext());
    this.devicesAdapter = new DeviceAdapter(this, R.layout.list_device_item, new ArrayList<>());
    this.lv_scan.setAdapter(this.devicesAdapter);


    this.btManager= (BluetoothManager) this.getSystemService(Context.BLUETOOTH_SERVICE);
    mBTAdapter = this.btManager.getAdapter();

    bluetoothLeScanner = this.mBTAdapter.getBluetoothLeScanner();


    this.devices_connections = new HashMap<>();
    this.devices_to_attack = new ConcurrentLinkedQueue<>();
    this.scanning = false;
    this.updateStatus();

    this.devicesAdapter.notifyDataSetChanged();
}
 
Example #13
Source File: RemovePollRace.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
Collection<Queue<Boolean>> concurrentQueues() {
    List<Queue<Boolean>> queues = new ArrayList<Queue<Boolean>>();
    queues.add(new ConcurrentLinkedDeque<Boolean>());
    queues.add(new ConcurrentLinkedQueue<Boolean>());
    queues.add(new ArrayBlockingQueue<Boolean>(count, false));
    queues.add(new ArrayBlockingQueue<Boolean>(count, true));
    queues.add(new LinkedBlockingQueue<Boolean>());
    queues.add(new LinkedBlockingDeque<Boolean>());
    queues.add(new LinkedTransferQueue<Boolean>());

    // Following additional implementations are available from:
    // http://gee.cs.oswego.edu/dl/concurrency-interest/index.html
    // queues.add(new SynchronizedLinkedListQueue<Boolean>());

    // Avoid "first fast, second slow" benchmark effect.
    Collections.shuffle(queues);
    return queues;
}
 
Example #14
Source File: MultiThreadParentTaskDataFetcher.java    From incubator-nemo with Apache License 2.0 5 votes vote down vote up
MultiThreadParentTaskDataFetcher(final IRVertex dataSource,
                                 final InputReader readerForParentTask,
                                 final OutputCollector outputCollector) {
  super(dataSource, outputCollector);
  this.readersForParentTask = readerForParentTask;
  this.firstFetch = true;
  this.elementQueue = new ConcurrentLinkedQueue();
  this.queueInsertionThreads = Executors.newCachedThreadPool();
}
 
Example #15
Source File: MetricsRegistry.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
/**
 * Get the snapshot list for the given log channel ID. If no list is available, one is created (and stored).
 *
 * @param logChannelId
 *          The log channel to use.
 * @return an existing or a new metrics snapshot list.
 */
public Queue<MetricsSnapshotInterface> getSnapshotList( String logChannelId ) {
  Queue<MetricsSnapshotInterface> list = snapshotLists.get( logChannelId );
  if ( list == null ) {
    list = new ConcurrentLinkedQueue<MetricsSnapshotInterface>();
    snapshotLists.put( logChannelId, list );
  }
  return list;

}
 
Example #16
Source File: QueueUtilTest.java    From vjtools with Apache License 2.0 5 votes vote down vote up
@Test
public void guavaBuildSet() {
	ArrayDeque<String> queue1 = QueueUtil.newArrayDeque(16);
	LinkedList<String> queue2 = QueueUtil.newLinkedDeque();

	ConcurrentLinkedQueue<String> queue3 = QueueUtil.newConcurrentNonBlockingQueue();
	Deque<String> queue7 = QueueUtil.newConcurrentNonBlockingDeque();

	LinkedBlockingQueue<String> queue4 = QueueUtil.newBlockingUnlimitQueue();
	LinkedBlockingDeque<String> queue8 = QueueUtil.newBlockingUnlimitDeque();

	LinkedBlockingQueue<String> queue5 = QueueUtil.newLinkedBlockingQueue(100);
	ArrayBlockingQueue<String> queue6 = QueueUtil.newArrayBlockingQueue(100);
	LinkedBlockingDeque<String> queue9 = QueueUtil.newBlockingDeque(100);
}
 
Example #17
Source File: ClusterMaintenanceModeFlowEventChainFactory.java    From cloudbreak with Apache License 2.0 5 votes vote down vote up
@Override
public Queue<Selectable> createFlowTriggerEventQueue(MaintenanceModeValidationTriggerEvent event) {
    Queue<Selectable> flowEventChain = new ConcurrentLinkedQueue<>();
    flowEventChain.add(new StackSyncTriggerEvent(StackSyncEvent.STACK_SYNC_EVENT.event(), event.getResourceId(), true, event.accepted()));
    flowEventChain.add(new StackEvent(CLUSTER_SYNC_EVENT.event(), event.getResourceId()));
    flowEventChain.add(new MaintenanceModeValidationTriggerEvent(
            MaintenanceModeValidationEvent.START_VALIDATION_FLOW_EVENT.event(), event.getResourceId()));
    return flowEventChain;
}
 
Example #18
Source File: TransportIndicesShardStoresAction.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
AsyncShardStoresInfoFetches(DiscoveryNodes nodes, RoutingNodes routingNodes, MetaData metaData, Set<ShardId> shardIds, ActionListener<IndicesShardStoresResponse> listener) {
    this.nodes = nodes;
    this.routingNodes = routingNodes;
    this.metaData = metaData;
    this.shardIds = shardIds;
    this.listener = listener;
    this.fetchResponses = new ConcurrentLinkedQueue<>();
    this.expectedOps = new CountDown(shardIds.size());
}
 
Example #19
Source File: KeyedProcessOperatorTest.java    From flink with Apache License 2.0 5 votes vote down vote up
/**
 * Verifies that we don't have leakage between different keys.
 */
@Test
public void testEventTimeTimerWithState() throws Exception {

	KeyedProcessOperator<Integer, Integer, String> operator =
			new KeyedProcessOperator<>(new TriggeringStatefulFlatMapFunction(TimeDomain.EVENT_TIME));

	OneInputStreamOperatorTestHarness<Integer, String> testHarness =
			new KeyedOneInputStreamOperatorTestHarness<>(operator, new IdentityKeySelector<Integer>(), BasicTypeInfo.INT_TYPE_INFO);

	testHarness.setup();
	testHarness.open();

	testHarness.processWatermark(new Watermark(1));
	testHarness.processElement(new StreamRecord<>(17, 0L)); // should set timer for 6
	testHarness.processElement(new StreamRecord<>(13, 0L)); // should set timer for 6

	testHarness.processWatermark(new Watermark(2));
	testHarness.processElement(new StreamRecord<>(42, 1L)); // should set timer for 7
	testHarness.processElement(new StreamRecord<>(13, 1L)); // should delete timer

	testHarness.processWatermark(new Watermark(6));
	testHarness.processWatermark(new Watermark(7));

	ConcurrentLinkedQueue<Object> expectedOutput = new ConcurrentLinkedQueue<>();

	expectedOutput.add(new Watermark(1L));
	expectedOutput.add(new StreamRecord<>("INPUT:17", 0L));
	expectedOutput.add(new StreamRecord<>("INPUT:13", 0L));
	expectedOutput.add(new Watermark(2L));
	expectedOutput.add(new StreamRecord<>("INPUT:42", 1L));
	expectedOutput.add(new StreamRecord<>("STATE:17", 6L));
	expectedOutput.add(new Watermark(6L));
	expectedOutput.add(new StreamRecord<>("STATE:42", 7L));
	expectedOutput.add(new Watermark(7L));

	TestHarnessUtil.assertOutputEquals("Output was not correct.", expectedOutput, testHarness.getOutput());

	testHarness.close();
}
 
Example #20
Source File: KeyedProcessOperatorTest.java    From flink with Apache License 2.0 5 votes vote down vote up
/**
 * This also verifies that the timestamps ouf side-emitted records is correct.
 */
@Test
public void testSideOutput() throws Exception {
	KeyedProcessOperator<Integer, Integer, String> operator = new KeyedProcessOperator<>(new SideOutputProcessFunction());

	OneInputStreamOperatorTestHarness<Integer, String> testHarness =
		new KeyedOneInputStreamOperatorTestHarness<>(
			operator, new IdentityKeySelector<>(), BasicTypeInfo.INT_TYPE_INFO);

	testHarness.setup();
	testHarness.open();

	testHarness.processElement(new StreamRecord<>(42, 17L /* timestamp */));

	ConcurrentLinkedQueue<Object> expectedOutput = new ConcurrentLinkedQueue<>();

	expectedOutput.add(new StreamRecord<>("IN:42", 17L /* timestamp */));

	TestHarnessUtil.assertOutputEquals("Output was not correct.", expectedOutput, testHarness.getOutput());

	ConcurrentLinkedQueue<StreamRecord<Integer>> expectedIntSideOutput = new ConcurrentLinkedQueue<>();
	expectedIntSideOutput.add(new StreamRecord<>(42, 17L /* timestamp */));
	ConcurrentLinkedQueue<StreamRecord<Integer>> intSideOutput =
		testHarness.getSideOutput(SideOutputProcessFunction.INTEGER_OUTPUT_TAG);
	TestHarnessUtil.assertOutputEquals(
		"Side output was not correct.",
		expectedIntSideOutput,
		intSideOutput);

	ConcurrentLinkedQueue<StreamRecord<Long>> expectedLongSideOutput = new ConcurrentLinkedQueue<>();
	expectedLongSideOutput.add(new StreamRecord<>(42L, 17L /* timestamp */));
	ConcurrentLinkedQueue<StreamRecord<Long>> longSideOutput =
		testHarness.getSideOutput(SideOutputProcessFunction.LONG_OUTPUT_TAG);
	TestHarnessUtil.assertOutputEquals(
		"Side output was not correct.",
		expectedLongSideOutput,
		longSideOutput);

	testHarness.close();
}
 
Example #21
Source File: ActorBalancingOnRuntime.java    From actor4j-core with Apache License 2.0 5 votes vote down vote up
public ActorBalancingOnRuntime() {
	super();
	
	balancedThreadsQueue = new ConcurrentLinkedQueue<>();
	pollThreadIndex = new AtomicInteger(0);
	
	lock = new ReentrantLock();
}
 
Example #22
Source File: EventTimeOrderingOperatorTest.java    From flink-connectors with Apache License 2.0 5 votes vote down vote up
@Test
public void testLateElements() throws Exception {
    testHarness.processWatermark(1L);
    assertEquals(1L, operator.lastWatermark);
    testHarness.processElement(record(K1, 0L));
    testHarness.processElement(record(K1, 1L));
    testHarness.processWatermark(2L);
    assertEquals(2L, operator.lastWatermark);

    Queue<Object> actual = testHarness.getOutput();
    Queue<Object> expected = new ConcurrentLinkedQueue<>();
    expected.add(watermark(1L));
    expected.add(watermark(2L));
    TestHarnessUtil.assertOutputEquals("Unexpected output", expected, actual);
}
 
Example #23
Source File: LegacyKeyedCoProcessOperatorTest.java    From flink with Apache License 2.0 5 votes vote down vote up
/**
 * Verifies that we don't have leakage between different keys.
 */
@Test
public void testProcessingTimeTimerWithState() throws Exception {

	LegacyKeyedCoProcessOperator<String, Integer, String, String> operator =
			new LegacyKeyedCoProcessOperator<>(new ProcessingTimeTriggeringStatefulProcessFunction());

	TwoInputStreamOperatorTestHarness<Integer, String, String> testHarness =
			new KeyedTwoInputStreamOperatorTestHarness<>(
					operator,
					new IntToStringKeySelector<>(),
					new IdentityKeySelector<String>(),
					BasicTypeInfo.STRING_TYPE_INFO);

	testHarness.setup();
	testHarness.open();

	testHarness.setProcessingTime(1);
	testHarness.processElement1(new StreamRecord<>(17)); // should set timer for 6
	testHarness.processElement1(new StreamRecord<>(13)); // should set timer for 6

	testHarness.setProcessingTime(2);
	testHarness.processElement1(new StreamRecord<>(13)); // should delete timer again
	testHarness.processElement2(new StreamRecord<>("42")); // should set timer for 7

	testHarness.setProcessingTime(6);
	testHarness.setProcessingTime(7);

	ConcurrentLinkedQueue<Object> expectedOutput = new ConcurrentLinkedQueue<>();

	expectedOutput.add(new StreamRecord<>("INPUT1:17"));
	expectedOutput.add(new StreamRecord<>("INPUT1:13"));
	expectedOutput.add(new StreamRecord<>("INPUT2:42"));
	expectedOutput.add(new StreamRecord<>("STATE:17"));
	expectedOutput.add(new StreamRecord<>("STATE:42"));

	TestHarnessUtil.assertOutputEquals("Output was not correct.", expectedOutput, testHarness.getOutput());

	testHarness.close();
}
 
Example #24
Source File: SQLQueueComponent.java    From litchi with Apache License 2.0 5 votes vote down vote up
protected ConcurrentLinkedQueue<DbQueueModel> getQueue(Table<?> table) {
    synchronized (syncLock) {
        ConcurrentLinkedQueue<DbQueueModel> queue = TABLE_QUEUE.get(table.tableName());
        if (queue == null) {
            queue = new ConcurrentLinkedQueue<>();
            TABLE_QUEUE.putIfAbsent(table.tableName(), queue);
            TABLE_INFO.putIfAbsent(table.tableName(), table.getTableInfo());
        }
        return queue;
    }
}
 
Example #25
Source File: LegacyKeyedProcessOperatorTest.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
/**
 * Verifies that we don't have leakage between different keys.
 */
@Test
public void testProcessingTimeTimerWithState() throws Exception {

	LegacyKeyedProcessOperator<Integer, Integer, String> operator =
			new LegacyKeyedProcessOperator<>(new TriggeringStatefulFlatMapFunction(TimeDomain.PROCESSING_TIME));

	OneInputStreamOperatorTestHarness<Integer, String> testHarness =
			new KeyedOneInputStreamOperatorTestHarness<>(operator, new IdentityKeySelector<Integer>(), BasicTypeInfo.INT_TYPE_INFO);

	testHarness.setup();
	testHarness.open();

	testHarness.setProcessingTime(1);
	testHarness.processElement(new StreamRecord<>(17)); // should set timer for 6

	testHarness.setProcessingTime(2);
	testHarness.processElement(new StreamRecord<>(42)); // should set timer for 7

	testHarness.setProcessingTime(6);
	testHarness.setProcessingTime(7);

	ConcurrentLinkedQueue<Object> expectedOutput = new ConcurrentLinkedQueue<>();

	expectedOutput.add(new StreamRecord<>("INPUT:17"));
	expectedOutput.add(new StreamRecord<>("INPUT:42"));
	expectedOutput.add(new StreamRecord<>("STATE:17"));
	expectedOutput.add(new StreamRecord<>("STATE:42"));

	TestHarnessUtil.assertOutputEquals("Output was not correct.", expectedOutput, testHarness.getOutput());

	testHarness.close();
}
 
Example #26
Source File: InterModComms.java    From patchwork-api with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Retrieve pending messages for your modid. Use the predicate to filter the method name.
 *
 * @param modId the modid you are querying for
 * @param methodMatcher a predicate for the method you are interested in
 * @return All messages passing the supplied method predicate
 */
public static Stream<IMCMessage> getMessages(final String modId, final Predicate<String> methodMatcher) {
	ConcurrentLinkedQueue<IMCMessage> queue = containerQueues.get(modId);

	if (queue == null) {
		return Stream.empty();
	}

	return StreamSupport.stream(new QueueFilteringSpliterator(queue, methodMatcher), false);
}
 
Example #27
Source File: FragmentQueueProcessor.java    From amidst with GNU General Public License v3.0 5 votes vote down vote up
@CalledByAny
public FragmentQueueProcessor(
		ConcurrentLinkedQueue<Fragment> availableQueue,
		ConcurrentLinkedQueue<Fragment> loadingQueue,
		ConcurrentLinkedQueue<Fragment> recycleQueue,
		FragmentCache cache,
		LayerManager layerManager,
		Setting<Dimension> dimensionSetting) {
	this.availableQueue = availableQueue;
	this.loadingQueue = loadingQueue;
	this.recycleQueue = recycleQueue;
	this.cache = cache;
	this.layerManager = layerManager;
	this.dimensionSetting = dimensionSetting;
}
 
Example #28
Source File: CoBroadcastWithNonKeyedOperatorTest.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
@Test
public void testSideOutput() throws Exception {
	try (
			TwoInputStreamOperatorTestHarness<String, Integer, String> testHarness = getInitializedTestHarness(
					new FunctionWithSideOutput(), STATE_DESCRIPTOR)
	) {

		testHarness.processWatermark1(new Watermark(10L));
		testHarness.processWatermark2(new Watermark(10L));
		testHarness.processElement2(new StreamRecord<>(5, 12L));

		testHarness.processWatermark1(new Watermark(40L));
		testHarness.processWatermark2(new Watermark(40L));
		testHarness.processElement1(new StreamRecord<>("6", 13L));
		testHarness.processElement1(new StreamRecord<>("6", 15L));

		testHarness.processWatermark1(new Watermark(50L));
		testHarness.processWatermark2(new Watermark(50L));

		ConcurrentLinkedQueue<StreamRecord<String>> expectedBr = new ConcurrentLinkedQueue<>();
		expectedBr.add(new StreamRecord<>("BR:5 WM:10 TS:12", 12L));

		ConcurrentLinkedQueue<StreamRecord<String>> expectedNonBr = new ConcurrentLinkedQueue<>();
		expectedNonBr.add(new StreamRecord<>("NON-BR:6 WM:40 TS:13", 13L));
		expectedNonBr.add(new StreamRecord<>("NON-BR:6 WM:40 TS:15", 15L));

		ConcurrentLinkedQueue<StreamRecord<String>> brSideOutput = testHarness.getSideOutput(FunctionWithSideOutput.BROADCAST_TAG);
		ConcurrentLinkedQueue<StreamRecord<String>> nonBrSideOutput = testHarness.getSideOutput(FunctionWithSideOutput.NON_BROADCAST_TAG);

		TestHarnessUtil.assertOutputEquals("Wrong Side Output", expectedBr, brSideOutput);
		TestHarnessUtil.assertOutputEquals("Wrong Side Output", expectedNonBr, nonBrSideOutput);
	}
}
 
Example #29
Source File: WhiteBox.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Actions that remove the first element, and are expected to
 * leave at most one slack dead node at head.
 */
@DataProvider
public Object[][] pollActions() {
    return List.<Consumer<ConcurrentLinkedQueue>>of(
        q -> assertNotNull(q.poll()),
        q -> assertNotNull(q.remove()))
        .stream().map(x -> new Object[]{ x }).toArray(Object[][]::new);
}
 
Example #30
Source File: FulgoraMapEmitter.java    From titan1withtp3.1 with Apache License 2.0 5 votes vote down vote up
@Override
public void emit(K key, V value) {
    if (this.doReduce)
        this.reduceMap.computeIfAbsent(key, k -> new ConcurrentLinkedQueue<>()).add(value);
    else
        this.mapQueue.add(new KeyValue<>(key, value));
}