Search in sources :

Example 1 with CircularFifoBuffer

use of org.apache.commons.collections.buffer.CircularFifoBuffer in project geode by apache.

the class PulseControllerJUnitTest method setup.

@Before
public void setup() throws Exception {
    this.mockMvc = MockMvcBuilders.webAppContextSetup(this.wac).build();
    cluster = Mockito.spy(Cluster.class);
    Cluster.Region region = new Cluster.Region();
    region.setName(REGION_NAME);
    region.setFullPath(REGION_PATH);
    region.setRegionType(REGION_TYPE);
    region.setMemberCount(1);
    region.setMemberName(new ArrayList<String>() {

        {
            add(MEMBER_NAME);
        }
    });
    region.setPutsRate(12.31D);
    region.setGetsRate(27.99D);
    Cluster.RegionOnMember regionOnMember = new Cluster.RegionOnMember();
    regionOnMember.setRegionFullPath(REGION_PATH);
    regionOnMember.setMemberName(MEMBER_NAME);
    region.setRegionOnMembers(new ArrayList<Cluster.RegionOnMember>() {

        {
            add(regionOnMember);
        }
    });
    cluster.addClusterRegion(REGION_PATH, region);
    Cluster.Member member = new Cluster.Member();
    member.setId(MEMBER_ID);
    member.setName(MEMBER_NAME);
    member.setUptime(1L);
    member.setHost(PHYSICAL_HOST_NAME);
    member.setGemfireVersion(GEMFIRE_VERSION);
    member.setCpuUsage(55.77123D);
    member.setMemberRegions(new HashMap<String, Cluster.Region>() {

        {
            put(REGION_NAME, region);
        }
    });
    Cluster.AsyncEventQueue aeq = new Cluster.AsyncEventQueue();
    aeq.setAsyncEventListener(AEQ_LISTENER);
    member.setAsyncEventQueueList(new ArrayList() {

        {
            add(aeq);
        }
    });
    Cluster.Client client = new Cluster.Client();
    client.setId("100");
    client.setName(CLIENT_NAME);
    client.setUptime(1L);
    member.setMemberClientsHMap(new HashMap<String, Cluster.Client>() {

        {
            put(CLIENT_NAME, client);
        }
    });
    cluster.setMembersHMap(new HashMap() {

        {
            put(MEMBER_NAME, member);
        }
    });
    cluster.setPhysicalToMember(new HashMap() {

        {
            put(PHYSICAL_HOST_NAME, new ArrayList() {

                {
                    add(member);
                }
            });
        }
    });
    cluster.setServerName(CLUSTER_NAME);
    cluster.setMemoryUsageTrend(new CircularFifoBuffer() {

        {
            add(1);
            add(2);
            add(3);
        }
    });
    cluster.setWritePerSecTrend(new CircularFifoBuffer() {

        {
            add(1.29);
            add(2.3);
            add(3.0);
        }
    });
    cluster.setThroughoutReadsTrend(new CircularFifoBuffer() {

        {
            add(1);
            add(2);
            add(3);
        }
    });
    cluster.setThroughoutWritesTrend(new CircularFifoBuffer() {

        {
            add(4);
            add(5);
            add(6);
        }
    });
    Repository repo = Mockito.spy(Repository.class);
    // Set up a partial mock for some static methods
    spy(Repository.class);
    when(Repository.class, "get").thenReturn(repo);
    doReturn(cluster).when(repo).getCluster();
    PulseConfig config = new PulseConfig();
    File tempQueryLog = tempFolder.newFile("query_history.log");
    config.setQueryHistoryFileName(tempQueryLog.toString());
    doReturn(config).when(repo).getPulseConfig();
    PulseController.pulseVersion.setPulseVersion("not empty");
    PulseController.pulseVersion.setPulseBuildId("not empty");
    PulseController.pulseVersion.setPulseBuildDate("not empty");
    PulseController.pulseVersion.setPulseSourceDate("not empty");
    PulseController.pulseVersion.setPulseSourceRevision("not empty");
    PulseController.pulseVersion.setPulseSourceRepository("not empty");
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Cluster(org.apache.geode.tools.pulse.internal.data.Cluster) Matchers.anyString(org.mockito.Matchers.anyString) CircularFifoBuffer(org.apache.commons.collections.buffer.CircularFifoBuffer) Repository(org.apache.geode.tools.pulse.internal.data.Repository) PulseConfig(org.apache.geode.tools.pulse.internal.data.PulseConfig) File(java.io.File) Before(org.junit.Before)

Example 2 with CircularFifoBuffer

use of org.apache.commons.collections.buffer.CircularFifoBuffer in project hbase by apache.

the class WALProcedureStore method start.

@Override
public void start(int numSlots) throws IOException {
    if (!setRunning(true)) {
        return;
    }
    // Init buffer slots
    loading.set(true);
    runningProcCount = numSlots;
    syncMaxSlot = numSlots;
    slots = new ByteSlot[numSlots];
    slotsCache = new LinkedTransferQueue();
    while (slotsCache.size() < numSlots) {
        slotsCache.offer(new ByteSlot());
    }
    // Tunings
    walCountWarnThreshold = conf.getInt(WAL_COUNT_WARN_THRESHOLD_CONF_KEY, DEFAULT_WAL_COUNT_WARN_THRESHOLD);
    maxRetriesBeforeRoll = conf.getInt(MAX_RETRIES_BEFORE_ROLL_CONF_KEY, DEFAULT_MAX_RETRIES_BEFORE_ROLL);
    maxSyncFailureRoll = conf.getInt(MAX_SYNC_FAILURE_ROLL_CONF_KEY, DEFAULT_MAX_SYNC_FAILURE_ROLL);
    waitBeforeRoll = conf.getInt(WAIT_BEFORE_ROLL_CONF_KEY, DEFAULT_WAIT_BEFORE_ROLL);
    rollRetries = conf.getInt(ROLL_RETRIES_CONF_KEY, DEFAULT_ROLL_RETRIES);
    rollThreshold = conf.getLong(ROLL_THRESHOLD_CONF_KEY, DEFAULT_ROLL_THRESHOLD);
    periodicRollMsec = conf.getInt(PERIODIC_ROLL_CONF_KEY, DEFAULT_PERIODIC_ROLL);
    syncWaitMsec = conf.getInt(SYNC_WAIT_MSEC_CONF_KEY, DEFAULT_SYNC_WAIT_MSEC);
    useHsync = conf.getBoolean(USE_HSYNC_CONF_KEY, DEFAULT_USE_HSYNC);
    // WebUI
    syncMetricsBuffer = new CircularFifoBuffer(conf.getInt(STORE_WAL_SYNC_STATS_COUNT, DEFAULT_SYNC_STATS_COUNT));
    // Init sync thread
    syncThread = new Thread("WALProcedureStoreSyncThread") {

        @Override
        public void run() {
            try {
                syncLoop();
            } catch (Throwable e) {
                LOG.error("Got an exception from the sync-loop", e);
                if (!isSyncAborted()) {
                    sendAbortProcessSignal();
                }
            }
        }
    };
    syncThread.start();
}
Also used : CircularFifoBuffer(org.apache.commons.collections.buffer.CircularFifoBuffer) LinkedTransferQueue(java.util.concurrent.LinkedTransferQueue) ByteSlot(org.apache.hadoop.hbase.procedure2.util.ByteSlot)

Example 3 with CircularFifoBuffer

use of org.apache.commons.collections.buffer.CircularFifoBuffer in project gocd by gocd.

the class GoArtifactsManipulatorTest method shouldBombWithErrorWhenStatusCodeReturnedIsRequestEntityTooLarge.

@Test
public void shouldBombWithErrorWhenStatusCodeReturnedIsRequestEntityTooLarge() throws IOException, InterruptedException {
    long size = anyLong();
    when(httpService.upload(any(String.class), size, any(File.class), any(Properties.class))).thenReturn(HttpServletResponse.SC_REQUEST_ENTITY_TOO_LARGE);
    CircularFifoBuffer buffer = (CircularFifoBuffer) 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: " + size + ") 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));
        }
    }
}
Also used : Properties(java.util.Properties) File(java.io.File) CircularFifoBuffer(org.apache.commons.collections.buffer.CircularFifoBuffer) Test(org.junit.Test)

Example 4 with CircularFifoBuffer

use of org.apache.commons.collections.buffer.CircularFifoBuffer in project gocd by gocd.

the class ConsoleOutputTransmitter method flushToServer.

public void flushToServer() {
    if (buffer.isEmpty()) {
        return;
    }
    List sent = new ArrayList();
    try {
        synchronized (buffer) {
            while (!buffer.isEmpty()) {
                sent.add(buffer.remove());
            }
        }
        StringBuilder result = new StringBuilder();
        for (Object string : sent) {
            result.append(string);
            result.append("\n");
        }
        consoleAppender.append(result.toString());
    } catch (IOException e) {
        LOGGER.warn("Could not send console output to server", e);
        //recreate buffer
        synchronized (buffer) {
            sent.addAll(buffer);
            buffer = new CircularFifoBuffer(10 * 1024);
            buffer.addAll(sent);
        }
    }
}
Also used : ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) IOException(java.io.IOException) CircularFifoBuffer(org.apache.commons.collections.buffer.CircularFifoBuffer)

Example 5 with CircularFifoBuffer

use of org.apache.commons.collections.buffer.CircularFifoBuffer in project engine by craftercms.

the class CircularQueueLogAppender method activateOptions.

@Override
public void activateOptions() {
    super.activateOptions();
    if (maxQueueSize <= 0) {
        throw new IllegalArgumentException("maxQueueSize must be a integer bigger that 0");
    }
    buffer = BufferUtils.synchronizedBuffer(new CircularFifoBuffer(maxQueueSize));
    instance = this;
    dateFormat = new SimpleDateFormat(dateFormatString);
}
Also used : CircularFifoBuffer(org.apache.commons.collections.buffer.CircularFifoBuffer) SimpleDateFormat(java.text.SimpleDateFormat)

Aggregations

CircularFifoBuffer (org.apache.commons.collections.buffer.CircularFifoBuffer)5 File (java.io.File)2 ArrayList (java.util.ArrayList)2 IOException (java.io.IOException)1 SimpleDateFormat (java.text.SimpleDateFormat)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Properties (java.util.Properties)1 LinkedTransferQueue (java.util.concurrent.LinkedTransferQueue)1 Cluster (org.apache.geode.tools.pulse.internal.data.Cluster)1 PulseConfig (org.apache.geode.tools.pulse.internal.data.PulseConfig)1 Repository (org.apache.geode.tools.pulse.internal.data.Repository)1 ByteSlot (org.apache.hadoop.hbase.procedure2.util.ByteSlot)1 Before (org.junit.Before)1 Test (org.junit.Test)1 Matchers.anyString (org.mockito.Matchers.anyString)1