Package com.netflix.suro.sink.localfile

Examples of com.netflix.suro.sink.localfile.LocalFileSink$SpaceChecker


        final ObjectMapper jsonMapper = new DefaultObjectMapper();

        LocalFileSink.SpaceChecker spaceChecker = mock(LocalFileSink.SpaceChecker.class);

        LocalFileSink sink = new LocalFileSink(
                tempDir.newFolder().getAbsolutePath(),
                null,
                null,
                0,
                "PT1s",
                10,
                new MemoryQueue4Sink(10000),
                100,
                1000,
                true,
                spaceChecker
        );
        sink.open();

        SinkManager sinks = new SinkManager();
        sinks.initialSet(new ImmutableMap.Builder<String, Sink>()
                .put("local", sink).build());

        RoutingMap map = new RoutingMap();
        map.set(new ImmutableMap.Builder<String, RoutingMap.RoutingInfo>()
                .put(TOPIC_NAME, new RoutingMap.RoutingInfo(Lists.newArrayList(new RoutingMap.Route("local", null, null)), null))
                .build());

        MessageSetProcessor msgProcessor = new MessageSetProcessor(
                new Queue4Server(config),
                new MessageRouter(map, sinks, jsonMapper),
                config,
                jsonMapper
        );

        ThriftServer server = new ThriftServer(config, msgProcessor);
        server.start();

        SuroClient client = createSuroClient(server.getPort());

        Thread t = createClientThread(jsonMapper, client, TOPIC_NAME);

        // checking the traffic goes
        for (int i = 0; i < 10; ++i) {
            if (client.getSentMessageCount() > 0) {
                break;
            }
            Thread.sleep(1000);
        }
        assertTrue(client.getSentMessageCount() > 0);

        // shutting down the traffic
        hasEnoughSpace = false;
        int count = 0;
        while (count < 3) {
            if (msgProcessor.getStatus() == ServiceStatus.WARNING) {
                ++count;
            }
        }
        assertEquals(count, 3);

        client.shutdown();
        run.set(false);
        t.join();

        // resuming the traffic
        hasEnoughSpace = true;
        run.set(true);
        SuroClient newClient = createSuroClient(server.getPort());
        t = createClientThread(jsonMapper, newClient, TOPIC_NAME);

        for (int i = 0; i < 10; ++i) {
            if (client.getSentMessageCount() > 0) {
                break;
            }
            Thread.sleep(1000);
        }
        assertTrue(client.getSentMessageCount() > 0);

        run.set(false);
        t.join();
        client.shutdown();

        server.shutdown();

        sink.close();

        assertEquals(sink.getNumOfPendingMessages(), 0);
    }
View Full Code Here

TOP

Related Classes of com.netflix.suro.sink.localfile.LocalFileSink$SpaceChecker

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.