org.apache.commons.collections4.queue.CircularFifoQueue Java Examples
The following examples show how to use
org.apache.commons.collections4.queue.CircularFifoQueue.
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: GoArtifactsManipulatorTest.java From gocd with Apache License 2.0 | 6 votes |
@Test public void shouldBombWithErrorWhenStatusCodeReturnedIsRequestEntityTooLarge() throws IOException, InterruptedException { when(httpService.upload(any(String.class), eq(tempFile.length()), any(File.class), any(Properties.class))).thenReturn(HttpServletResponse.SC_REQUEST_ENTITY_TOO_LARGE); CircularFifoQueue buffer = (CircularFifoQueue) ReflectionUtil.getField(ReflectionUtil.getField(goPublisher, "consoleOutputTransmitter"), "buffer"); synchronized (buffer) { try { goArtifactsManipulatorStub.publish(goPublisher, "some_dest", tempFile, jobIdentifier); fail("should have thrown request entity too large error"); } catch (RuntimeException e) { String expectedMessage = "Artifact upload for file " + tempFile.getAbsolutePath() + " (Size: "+ tempFile.length() +") was denied by the server. This usually happens when server runs out of disk space."; assertThat(e.getMessage(), is("java.lang.RuntimeException: " + expectedMessage + ". HTTP return code is 413")); assertThat(buffer.toString().contains(expectedMessage), is(true)); } } }
Example #2
Source File: XActorThread.java From actor4j-core with Apache License 2.0 | 6 votes |
public XActorThread(ThreadGroup group, String name, ActorSystemImpl system) { super(group, name, system); directiveQueue = new MpscArrayQueue<>(system.getQueueSize()); priorityQueue = new PriorityBlockingQueue<>(system.getQueueSize()); serverQueueL2 = new MpscArrayQueue<>(system.getQueueSize()); serverQueueL1 = new ArrayDeque<>(system.getBufferQueueSize()); outerQueueL2B = new MpscLinkedQueue8<>(); outerQueueL2A = new MpscArrayQueue<>(system.getQueueSize()); outerQueueL1 = new ArrayDeque<>(system.getBufferQueueSize()); innerQueueL2 = new LinkedList<>(); innerQueueL1 = new CircularFifoQueue<>(system.getQueueSize()); innerQueueAntiFloodingTimer = ((XActorSystemImpl)system).factoryAntiFloodingTimer.get(); outerQueueAntiFloodingTimer = ((XActorSystemImpl)system).factoryAntiFloodingTimer.get(); newMessage = new AtomicBoolean(true); }
Example #3
Source File: CircularFifoQueueUnitTest.java From tutorials with MIT License | 5 votes |
@Test public void givenAddElements_whenGetElement_correctElement() { CircularFifoQueue<String> colors = new CircularFifoQueue<>(5); colors.add("Red"); colors.add("Blue"); colors.add("Green"); colors.offer("White"); colors.offer("Black"); Assert.assertEquals(TEST_COLOR_BY_INDEX, colors.get(1)); }
Example #4
Source File: RateLimitTest.java From FlowSpaceFirewall with Apache License 2.0 | 5 votes |
@Test public void testRateLimitFast(){ RateTracker tracker = new RateTracker(2000,10000); CircularFifoQueue<Date> fifo = tracker.getFifo(); Date now = new Date(); for(int i =0; i< 1000;i++){ fifo.add(now); } assertTrue("Tracker Rate is " + tracker.getRate(), tracker.getRate() == (1000 * 1000)); }
Example #5
Source File: NodeClusterCoordinator.java From nifi with Apache License 2.0 | 5 votes |
@Override public List<NodeEvent> getNodeEvents(final NodeIdentifier nodeId) { final CircularFifoQueue<NodeEvent> eventQueue = nodeEvents.get(nodeId.getId()); if (eventQueue == null) { return Collections.emptyList(); } synchronized (eventQueue) { return new ArrayList<>(eventQueue); } }
Example #6
Source File: NodeClusterCoordinator.java From nifi with Apache License 2.0 | 5 votes |
private void addNodeEvent(final NodeIdentifier nodeId, final Severity severity, final String message) { final NodeEvent event = new Event(nodeId.toString(), message, severity); final CircularFifoQueue<NodeEvent> eventQueue = nodeEvents.computeIfAbsent(nodeId.getId(), id -> new CircularFifoQueue<>()); synchronized (eventQueue) { eventQueue.add(event); } }
Example #7
Source File: MockHistoryProcessor.java From deeplearning4j with Apache License 2.0 | 5 votes |
public MockHistoryProcessor(Configuration config) { this.config = config; history = new CircularFifoQueue<>(config.getHistoryLength()); recordCalls = new ArrayList<INDArray>(); addCalls = new ArrayList<INDArray>(); }
Example #8
Source File: CircularFifoQueueUnitTest.java From tutorials with MIT License | 5 votes |
@Test public void givenAddElements_whenUsingIntConstructor_correctSizeQueue() { CircularFifoQueue<String> colors = new CircularFifoQueue<>(5); colors.add("Red"); colors.add("Blue"); colors.add("Green"); colors.offer("White"); colors.offer("Black"); Assert.assertEquals(FIXED_SIZE, colors.maxSize()); }
Example #9
Source File: CircularFifoQueueUnitTest.java From tutorials with MIT License | 5 votes |
@Test public void whenUsingCollectionConstructor_correctSizeQueue() { List<String> days = new ArrayList<>(); days.add("Monday"); days.add("Tuesday"); days.add("Wednesday"); days.add("Thursday"); days.add("Friday"); days.add("Saturday"); days.add("Sunday"); CircularFifoQueue<String> daysOfWeek = new CircularFifoQueue<>(days); Assert.assertEquals(COLLECTION_SIZE, daysOfWeek.maxSize()); }
Example #10
Source File: NodeClusterCoordinator.java From localization_nifi with Apache License 2.0 | 5 votes |
@Override public List<NodeEvent> getNodeEvents(final NodeIdentifier nodeId) { final CircularFifoQueue<NodeEvent> eventQueue = nodeEvents.get(nodeId); if (eventQueue == null) { return Collections.emptyList(); } synchronized (eventQueue) { return new ArrayList<>(eventQueue); } }
Example #11
Source File: CircularFifoQueueUnitTest.java From tutorials with MIT License | 5 votes |
@Test public void givenAddElements_whenPollElement_correctElement() { CircularFifoQueue<String> colors = new CircularFifoQueue<>(5); colors.add("Red"); colors.add("Blue"); colors.add("Green"); colors.offer("White"); colors.offer("Black"); Assert.assertEquals(TEST_COLOR, colors.poll()); }
Example #12
Source File: CircularFifoQueueUnitTest.java From tutorials with MIT License | 5 votes |
@Test public void givenAddElements_whenPeekQueue_correctElement() { CircularFifoQueue<String> colors = new CircularFifoQueue<>(5); colors.add("Red"); colors.add("Blue"); colors.add("Green"); colors.offer("White"); colors.offer("Black"); Assert.assertEquals(TEST_COLOR, colors.peek()); }
Example #13
Source File: CircularFifoQueueUnitTest.java From tutorials with MIT License | 5 votes |
@Test public void givenAddElements_whenElementQueue_correctElement() { CircularFifoQueue<String> colors = new CircularFifoQueue<>(5); colors.add("Red"); colors.add("Blue"); colors.add("Green"); colors.offer("White"); colors.offer("Black"); Assert.assertEquals(TEST_COLOR, colors.element()); }
Example #14
Source File: CircularFifoQueueUnitTest.java From tutorials with MIT License | 5 votes |
@Test public void givenAddElements_whenRemoveElement_correctElement() { CircularFifoQueue<String> colors = new CircularFifoQueue<>(5); colors.add("Red"); colors.add("Blue"); colors.add("Green"); colors.offer("White"); colors.offer("Black"); Assert.assertEquals(TEST_COLOR, colors.remove()); }
Example #15
Source File: CircularFifoQueueUnitTest.java From tutorials with MIT License | 5 votes |
@Test public void givenFullQueue_whenClearQueue_getIsEmpty() { CircularFifoQueue<String> colors = new CircularFifoQueue<>(5); colors.add("Red"); colors.add("Blue"); colors.add("Green"); colors.offer("White"); colors.offer("Black"); colors.clear(); Assert.assertEquals(true, colors.isEmpty()); }
Example #16
Source File: CircularFifoQueueUnitTest.java From tutorials with MIT License | 5 votes |
@Test public void givenFullQueue_whenCheckFull_getIsFull() { CircularFifoQueue<String> colors = new CircularFifoQueue<>(5); colors.add("Red"); colors.add("Blue"); colors.add("Green"); colors.offer("White"); colors.offer("Black"); Assert.assertEquals(false, colors.isFull()); }
Example #17
Source File: CircularFifoQueueUnitTest.java From tutorials with MIT License | 5 votes |
@Test public void givenFullQueue_whenAddMoreElements_getIsAtFullCapacity() { CircularFifoQueue<String> colors = new CircularFifoQueue<>(5); colors.add("Red"); colors.add("Blue"); colors.add("Green"); colors.offer("White"); colors.offer("Black"); colors.add("Orange"); colors.add("Violet"); colors.add("Pink"); Assert.assertEquals(true, colors.isAtFullCapacity()); }
Example #18
Source File: JsonDataGeneratorImpl.java From json-data-generator with Apache License 2.0 | 5 votes |
private void setQueueCharacters(final CircularFifoQueue<Character> characters, final String string) { characters.clear(); char[] charArray = string.toCharArray(); for (int i = 0; i < charArray.length; i++) { characters.add(charArray[i]); } }
Example #19
Source File: CyclicStringBuffer.java From kafka-message-tool with MIT License | 5 votes |
public void resize(int size) { if (size <= 0) { throw new IllegalArgumentException("Size must be grater than zero but is " + size); } CircularFifoQueue<String> old = buffer; buffer = new CircularFifoQueue<>(size); copyElementsFrom(old); }
Example #20
Source File: JsonDataGeneratorImpl.java From json-data-generator with Apache License 2.0 | 5 votes |
private String readAsString(final CircularFifoQueue<Character> characters) { char[] charArray = new char[characters.size()]; for (int i = 0; i < charArray.length; i++) { charArray[i] = characters.get(i); } return new String(charArray); }
Example #21
Source File: EventCollector.java From document-management-software with GNU Lesser General Public License v3.0 | 5 votes |
/** * Puts the history in the relative FIFO * * @param history * @return true if it was not remembered already, false otherwise */ private boolean rememberHistory(History history) { Queue<Long> fifo = fifos.get(history.getClass().getName()); if (fifo == null) { fifo = new CircularFifoQueue<Long>(FIFO_SIZE); fifos.put(history.getClass().getName(), fifo); } if (fifo.contains(history.getId())) return false; else { fifo.add(history.getId()); return true; } }
Example #22
Source File: ConfSearch.java From OSPREY3 with GNU General Public License v2.0 | 5 votes |
/** * Create a splitter for a conformation search */ public MultiSplitter(ConfSearch confs) { this.confs = confs; buf = new CircularFifoQueue<>(); firstIndex = 0; streams = new ArrayList<>(); }
Example #23
Source File: XActorThread.java From actor4j-core with Apache License 2.0 | 5 votes |
@Override public void innerQueue(ActorMessage<?> message) { if (!((XActorSystemImpl)system).antiFloodingEnabled.get()) { if ((((CircularFifoQueue<ActorMessage<?>>)innerQueueL1).isAtFullCapacity() || !innerQueueL2.isEmpty())) { if (isDirective(message) || innerQueueAntiFloodingTimer.isInTimeRange()) innerQueueL2.offer(message); } else { innerQueueAntiFloodingTimer.inactive(); innerQueueL1.offer(message); } } else innerQueueL1.offer(message); }
Example #24
Source File: NodeClusterCoordinator.java From localization_nifi with Apache License 2.0 | 5 votes |
private void addNodeEvent(final NodeIdentifier nodeId, final Severity severity, final String message) { final NodeEvent event = new Event(nodeId.toString(), message, severity); final CircularFifoQueue<NodeEvent> eventQueue = nodeEvents.computeIfAbsent(nodeId, id -> new CircularFifoQueue<>()); synchronized (eventQueue) { eventQueue.add(event); } }
Example #25
Source File: DefaultActorThread.java From actor4j-core with Apache License 2.0 | 5 votes |
public DefaultActorThread(ThreadGroup group, String name, ActorSystemImpl system) { super(group, name, system); directiveQueue = new MpscArrayQueue<>(system.getQueueSize()); priorityQueue = new PriorityBlockingQueue<>(system.getQueueSize()); serverQueueL2 = new MpscArrayQueue<>(system.getQueueSize()); serverQueueL1 = new ArrayDeque<>(system.getBufferQueueSize()); outerQueueL2 = new MpscArrayQueue<>(system.getQueueSize()); outerQueueL1 = new ArrayDeque<>(system.getBufferQueueSize()); innerQueue = new CircularFifoQueue<>(system.getQueueSize()); newMessage = new AtomicBoolean(true); }
Example #26
Source File: ConfSearch.java From OSPREY3 with GNU General Public License v2.0 | 4 votes |
@Override public ScoredConf nextConf() { // where in the buffer should we read? long pos = index - firstIndex; // just in case assert (pos >= 0); assert (pos <= buf.size()); ScoredConf conf = null; // off the end? if (pos == buf.size()) { // read a new conf from the tree conf = confs.nextConf(); if (conf != null) { // if we're out of space, make a bigger queue if (buf.isAtFullCapacity()) { CircularFifoQueue<ScoredConf> newBuf = new CircularFifoQueue<>(buf.maxSize()*2); newBuf.addAll(buf); buf = newBuf; } buf.add(conf); } else { // end of the tree } } else { // read the conf from the buffer if (pos > Integer.MAX_VALUE) { throw new Error("Integer overflow! Conf buffer grew too large: " + pos); } conf = buf.get((int)pos); } if (conf != null) { index++; assert (index - firstIndex <= buf.size() + 1); } // prune the first conf from the buffer if everyone's read it if (pos == 0 && everyoneHasReadFirst()) { buf.remove(); firstIndex++; } return conf; }
Example #27
Source File: CyclicStringBuffer.java From kafka-message-tool with MIT License | 4 votes |
public CyclicStringBuffer(int size) { if (size <= 0) { throw new IllegalArgumentException("Size must be grater than zero but is " + size); } buffer = new CircularFifoQueue<>(size); }
Example #28
Source File: CyclicStringBuffer.java From kafka-message-tool with MIT License | 4 votes |
private void copyElementsFrom(CircularFifoQueue<String> old) { final Iterator<String> iterator = old.iterator(); while (iterator.hasNext()) { buffer.add(iterator.next()); } }
Example #29
Source File: ConsoleLoggerListener.java From grblcontroller with GNU General Public License v3.0 | 4 votes |
private ConsoleLoggerListener(){ this.loggedMessagesQueue = new CircularFifoQueue<>(Constants.CONSOLE_LOGGER_MAX_SIZE); this.messages = ""; }
Example #30
Source File: TestJobServerLogs.java From scheduling with GNU Affero General Public License v3.0 | 4 votes |
private void printDiagnosticMessage() { int LIMIT = 5; System.out.println("This test is going to fail, but before we print diagnostic message." + simpleDateFormat.format(new Date())); // iterate over all files in the 'logsLocation' for (File file : FileUtils.listFiles(new File(logsLocation), TrueFileFilter.INSTANCE, TrueFileFilter.INSTANCE)) { try { BasicFileAttributes attr = Files.readAttributes(file.toPath(), BasicFileAttributes.class); System.out.println(String.format("Name: %s, Size: %d, Created: %s, Modified: %s", file.getAbsolutePath(), attr.size(), attr.creationTime(), attr.lastModifiedTime())); BufferedReader br = new BufferedReader(new FileReader(file)); String line; int i; // print up to LIMIT first lines for (i = 0; i < LIMIT && (line = br.readLine()) != null; ++i) { System.out.println(line); } Queue<String> queue = new CircularFifoQueue<>(LIMIT); // reading last LIMIT lines for (; (line = br.readLine()) != null; ++i) { queue.add(line); } if (i >= LIMIT * 2) { // if there is more line than 2*LIMIT System.out.println("......."); System.out.println("....... (skipped content)"); System.out.println("......."); } for (String l : queue) { // print rest of the file System.out.println(l); } System.out.println("------------------------------------"); System.out.println(); } catch (IOException e) { System.out.println("Exception ocurred during accessing file attributes " + e); } } }