Example usage for java.util.concurrent TimeUnit HOURS

List of usage examples for java.util.concurrent TimeUnit HOURS

Introduction

In this page you can find the example usage for java.util.concurrent TimeUnit HOURS.

Prototype

TimeUnit HOURS

To view the source code for java.util.concurrent TimeUnit HOURS.

Click Source Link

Document

Time unit representing sixty minutes.

Usage

From source file:org.apache.pulsar.tests.integration.semantics.SemanticsTest.java

@Test(dataProvider = "ServiceUrls")
public void testBatchProducing(String serviceUrl) throws Exception {
    String topicName = generateTopicName("testbatchproducing", true);

    int numMessages = 10;

    List<MessageId> producedMsgIds;

    try (PulsarClient client = PulsarClient.builder().serviceUrl(serviceUrl).build()) {

        try (Consumer<String> consumer = client.newConsumer(Schema.STRING).topic(topicName)
                .subscriptionName("my-sub").subscribe()) {

            try (Producer<String> producer = client.newProducer(Schema.STRING).topic(topicName)
                    .enableBatching(true).batchingMaxMessages(5).batchingMaxPublishDelay(1, TimeUnit.HOURS)
                    .create()) {//  w ww . ja  v a 2s.  c o m

                List<CompletableFuture<MessageId>> sendFutures = Lists.newArrayList();
                for (int i = 0; i < numMessages; i++) {
                    sendFutures.add(producer.sendAsync("batch-message-" + i));
                }
                CompletableFuture.allOf(sendFutures.toArray(new CompletableFuture[numMessages])).get();
                producedMsgIds = sendFutures.stream().map(future -> future.join()).collect(Collectors.toList());
            }

            for (int i = 0; i < numMessages; i++) {
                Message<String> m = consumer.receive();
                assertEquals(producedMsgIds.get(i), m.getMessageId());
                assertEquals("batch-message-" + i, m.getValue());
            }
        }
    }

    // inspect the message ids
    for (int i = 0; i < 5; i++) {
        assertTrue(producedMsgIds.get(i) instanceof BatchMessageIdImpl);
        BatchMessageIdImpl mid = (BatchMessageIdImpl) producedMsgIds.get(i);
        log.info("Message {} id : {}", i, mid);

        assertEquals(i, mid.getBatchIndex());
    }
    for (int i = 5; i < 10; i++) {
        assertTrue(producedMsgIds.get(i) instanceof BatchMessageIdImpl);
        BatchMessageIdImpl mid = (BatchMessageIdImpl) producedMsgIds.get(i);
        log.info("Message {} id : {}", i, mid);

        assertEquals(i - 5, mid.getBatchIndex());
    }
}

From source file:org.wso2.carbon.bps.perf.rest.RestClientTest.java

public void execute() throws Exception {

    serverURL = config.getProperty("serverURL");
    ActivitiRestClient pretestClient = new ActivitiRestClient(serverURL, 1);
    JSONObject processDefs = pretestClient.getProcessDefinitions();
    try {//w ww .  j av  a 2s.co m
        JSONArray defs = processDefs.getJSONArray("data");
        for (int defNumber = 0; defNumber < defs.length(); defNumber++) {
            JSONObject def = defs.getJSONObject(defNumber);
            String pid = def.getString("id");
            String pkey = def.getString("key");
            processKeytoId.put(pkey, pid);
        }
    } catch (JSONException e) {
        log.error("Failed to get process definitions from the server: " + serverURL
                + ". Process definitions response: " + processDefs.toString());
    }

    instanceCount = Integer.parseInt(config.getProperty("instances"));

    List<Integer> threadNumbers = new ArrayList<>();
    String threadsProp = config.getProperty("threads");
    String[] threadParts = threadsProp.split(",");
    for (String threadPart : threadParts) {
        int threadCount = Integer.parseInt(threadPart.trim());
        threadNumbers.add(threadCount);
    }

    sleepTime = Integer.parseInt(config.getProperty("sleep"));
    outPath = config.getProperty("results");
    File outFolder = new File(outPath);
    if (!outFolder.exists()) {
        log.info("Results folder " + outFolder.getAbsolutePath() + " does not exist. Creating a new folder...");
        outFolder.mkdirs();
    }
    File testReportFile = new File(outFolder, "summary.csv");
    StringBuffer summaryBuffer = new StringBuffer();
    summaryBuffer.append("Server URL," + serverURL + "\n");
    summaryBuffer.append("Number of process instances," + instanceCount + "\n");
    summaryBuffer.append("Number of threads," + Arrays.toString(threadNumbers.toArray()) + "\n\n\n");
    log.info("Test configuration - \n" + summaryBuffer.toString());
    summaryBuffer.append("Process ID,Threads,Total time,TPS,Average execution time\n\n");
    FileUtils.write(testReportFile, summaryBuffer.toString());

    List<ProcessConfig> processConfigs = new ArrayList<>();
    String processRef = "process";
    Set<String> processPropsNames = config.stringPropertyNames();
    for (String processPropName : processPropsNames) {
        if (processPropName.startsWith(processRef)) {
            String processProp = config.getProperty(processPropName);
            ProcessConfig processConfig = new ProcessConfig(processProp, processKeytoId);
            processConfigs.add(processConfig);
            log.info("Test configuration created for the process " + processConfig.toString());
        }
    }

    boolean testFailures = false;
    long allTestsStartTime = System.currentTimeMillis();
    int numTotalTests = processConfigs.size() * threadNumbers.size();
    int numCompletedTests = 0;

    List<String> completedProcessNames = new ArrayList<>();
    log.info("Starting performance tests...");
    for (ProcessConfig processConfig : processConfigs) {
        log.info("Starting tests for process " + processConfig.getId());

        for (int numTreads : threadNumbers) {
            log.info("Starting test for process " + processConfig.getId() + " with " + numTreads
                    + " threads...");
            ActivitiRestClient client = new ActivitiRestClient(serverURL, numTreads);

            List<RestProcessExecutor> processExecutors = new ArrayList<>(instanceCount);
            ExecutorService executorService = Executors.newFixedThreadPool(numTreads);

            long stime = System.currentTimeMillis();
            for (int i = 0; i < instanceCount; i++) {
                RestProcessExecutor processExecutor = new RestProcessExecutor(null, processConfig.getId(),
                        processConfig.getStartupVariables(), client, i);
                processExecutors.add(processExecutor);
                executorService.execute(processExecutor);
            }

            executorService.shutdown();
            try {
                executorService.awaitTermination(1, TimeUnit.HOURS);
            } catch (InterruptedException e) {
                String msg = "Error occurred while waiting for executors to terminate.";
                log.error(msg, e);
            }
            long etime = System.currentTimeMillis();

            StringBuffer buf = new StringBuffer();
            double totalDuration = 0;
            buf.append("Instance durations for process: " + processConfig.getId() + "\n");
            for (RestProcessExecutor processExecutor : processExecutors) {
                testFailures = processExecutor.isFailed();
                if (testFailures) {
                    break;
                }

                buf.append(processExecutor.getExternalDuration() + "\n");
                totalDuration += processExecutor.getExternalDuration();
            }

            if (!testFailures) {
                double externalTPS = (double) instanceCount * 1000 / (double) (etime - stime);
                externalTPS = UMath.round(externalTPS, 3);

                double avgExeTime = totalDuration / instanceCount;
                avgExeTime = UMath.round(avgExeTime, 3);

                log.info("Test for process " + processConfig.getId() + " with " + numTreads
                        + " threads completed with duration: " + (etime - stime) + " ms | TPS: " + externalTPS
                        + " | Average execution time: " + avgExeTime);
                String processRecord = processConfig.getId() + "," + numTreads + "," + (etime - stime) + ","
                        + externalTPS + "," + avgExeTime + "\n";
                FileWriter fileWriter = new FileWriter(testReportFile, true);
                fileWriter.write(processRecord);
                fileWriter.close();

                buf.append("\n\nTPS," + externalTPS + "\n\n");
                buf.append("\n\nAverage execution time," + avgExeTime + " ms\n\n");

                File processReportFile = new File(outFolder, processConfig.getId() + ".csv");
                FileUtils.write(processReportFile, buf.toString());
                client.close();

                numCompletedTests++;
                double testingTime = System.currentTimeMillis() - allTestsStartTime;
                double testingTimeMinutes = UMath.round(testingTime / (1000 * 60), 2);
                double testingTimeHours = UMath.round(testingTime / (1000 * 60 * 60), 2);

                double remainingTime = (testingTime / numCompletedTests) * (numTotalTests - numCompletedTests);
                double remainingTimeMinutes = UMath.round(remainingTime / (1000 * 60), 2);
                double remainingTimeHours = UMath.round(remainingTime / (1000 * 60 * 60), 2);
                log.info("Completed test for process " + processConfig.getId() + " with " + numTreads
                        + " threads.");
                log.info(numCompletedTests + " out of " + numTotalTests + " completed in " + testingTimeMinutes
                        + " minutes (" + testingTimeHours + " hours). Estimated remaining time: "
                        + remainingTimeMinutes + " minutes (" + remainingTimeHours + " hours)");

                //                    client.undeploy();
                //                    client.deploy();

                completedProcessNames.add("Process: " + processConfig.getId() + " | Threads: " + numTreads);
                log.info("Waiting " + sleepTime + " ms before the next test");
                Thread.sleep(sleepTime);
            } else {
                log.error("Test for process " + processConfig.getId() + " with " + numTreads
                        + " failed. See client and server logs for more information.");
                break; // terminate tests for this process with other threads
            }
        }

        if (!testFailures) {
            log.info("Completed tests for process " + processConfig.getId());
        } else {
            log.error("At least one test for the process " + processConfig.getId()
                    + " has failed. Test suite will be terminated.");
            StringBuffer retryMessage = new StringBuffer();
            retryMessage.append("Below tests were completed successfully:\n");
            for (String completedProcessName : completedProcessNames) {
                retryMessage.append(completedProcessName + "\n");
            }
            log.info(retryMessage.toString());
            break; // terminate tests for other processes
        }
    }
}

From source file:org.xframium.device.artifact.AbstractArtifactProducer.java

protected Artifact generateHTMLRecord(Device device, String testName, String rootFolder, WebDriver webDriver) {
    CloudDescriptor currentCloud = CloudRegistry.instance().getCloud();
    if (device.getCloud() != null && !device.getCloud().isEmpty())
        currentCloud = CloudRegistry.instance().getCloud(device.getCloud());
    String cloudProvider = currentCloud.getProvider();

    StringBuffer stringBuffer = new StringBuffer();
    stringBuffer = new StringBuffer();
    stringBuffer.append("<html>");
    stringBuffer.append(//w ww .  j  a  va  2s .  c  o  m
            "<head><link href=\"http://fonts.googleapis.com/css?family=Roboto:300,400,500,700,400italic\" rel=\"stylesheet\"><link href=\"http://www.xframium.org/output/assets/css/toolkit-inverse.css\" rel=\"stylesheet\"><link href=\"http://www.xframium.org/output/assets/css/application.css\" rel=\"stylesheet\"><style>iframe {background-color: #eaeae1;} .abscenter { margin: auto; position: absolute; top: 0; left: 0; bottom: 0; right: 0; } .pass {color: #1bc98e;}.fail {color: #e64759;} .pageName { color: #e4d836; } .elementName { color: #e4d836; }</style></head>");

    int successCount = 0;
    int failureCount = 0;
    int ignoreCount = 0;
    int recordCount = 0;

    stringBuffer.append("<body><div class=\"container\">");

    stringBuffer.append(
            "<div class=\"col-sm-12 content\"><div class=\"dashhead\"><span class=\"pull-right text-muted\">")
            .append(simpleDateFormat.format(new Date(System.currentTimeMillis()))).append(" at ")
            .append(timeFormat.format(new Date(System.currentTimeMillis())))
            .append("</span><h6 class=\"dashhead-subtitle\">xFramium  " + Initializable.VERSION
                    + "</h6><h3 class=\"dashhead-title\">" + testName + "</h3><h6>" + device.getEnvironment()
                    + " on " + currentCloud.getHostName() + " (" + currentCloud.getProvider() + ")</h6>");

    if (webDriver instanceof PropertyProvider) {
        PropertyProvider pProvider = (PropertyProvider) webDriver;
        if (pProvider.getProperty("testDescription") != null
                && !pProvider.getProperty("testDescription").isEmpty())
            stringBuffer.append(
                    "<h6 class=\"text-muted\"><i>" + pProvider.getProperty("testDescription") + "</i></h6>");
    }

    stringBuffer.append("</div>");

    String panelClass = "default";
    if (DeviceManager.instance().getArtifacts(ArtifactType.EXECUTION_RECORD) != null
            && !DeviceManager.instance().getArtifacts(ArtifactType.EXECUTION_RECORD).isEmpty()) {
        panelClass = "success";
        long startTime = -1;
        long runTime = 0;
        for (Object item : DeviceManager.instance().getArtifacts(ArtifactType.EXECUTION_RECORD)) {
            ExecutionRecord eItem = (ExecutionRecord) item;

            if (startTime < 0)
                startTime = eItem.getTimeStamp();

            runTime += eItem.getRunTime();

            recordCount++;
            switch (eItem.getStatus()) {
            case FAILURE:
                failureCount++;
                panelClass = "danger";
                break;

            case FAILURE_IGNORED:
                ignoreCount++;
                break;

            case REPORT:
            case SUCCESS:
                successCount++;
            }

        }
        String runLength = String.format("%2dh %2dm %2ds", TimeUnit.MILLISECONDS.toHours(runTime),
                TimeUnit.MILLISECONDS.toMinutes(runTime)
                        - TimeUnit.HOURS.toMinutes(TimeUnit.MILLISECONDS.toHours(runTime)),
                TimeUnit.MILLISECONDS.toSeconds(runTime)
                        - TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes(runTime)));

        stringBuffer.append("<br /><div class=\"row statcards\"><div class=\"col-sm-1 m-b\"></div>");
        stringBuffer.append(
                "<div class=\"col-sm-2 m-b\"><div class=\"statcard statcard-success\"><div class=\"p-a\"><span class=\"statcard-desc\">Passed</span><h4 class=\"statcard-number\">"
                        + successCount + "</h4></div></div></div>");
        stringBuffer.append(
                "<div class=\"col-sm-2 m-b\"><div class=\"statcard statcard-warning\"><div class=\"p-a\"><span class=\"statcard-desc\">Ignored</span><h4 class=\"statcard-number\">"
                        + ignoreCount + "</h4></div></div></div>");
        stringBuffer.append(
                "<div class=\"col-sm-2 m-b\"><div class=\"statcard statcard-danger\"><div class=\"p-a\"><span class=\"statcard-desc\">Failed</span><h4 class=\"statcard-number\">"
                        + failureCount + "</h4></div></div></div>");
        stringBuffer.append(
                "<div class=\"col-sm-2 m-b\"><div class=\"statcard statcard-info\"><div class=\"p-a\"><span class=\"statcard-desc\">Total Steps</span><h4 class=\"statcard-number\">"
                        + recordCount + "</h4></div></div></div>");
        stringBuffer.append(
                "<div class=\"col-sm-2 m-b\"><div class=\"statcard statcard-info\"><div class=\"p-a\"><span class=\"statcard-desc\">Duration</span><h4 class=\"statcard-number\">"
                        + runLength + "</h4></div></div></div>");
        stringBuffer.append("</div><br />");
    }

    boolean success = true;
    int spaceCount = 0;
    if (DeviceManager.instance().getArtifacts(ArtifactType.EXECUTION_RECORD) != null
            && !DeviceManager.instance().getArtifacts(ArtifactType.EXECUTION_RECORD).isEmpty()) {
        for (Object item : DeviceManager.instance().getArtifacts(ArtifactType.EXECUTION_RECORD)) {
            ExecutionRecord eItem = (ExecutionRecord) item;

            if (eItem.getStatus().equals(StepStatus.FAILURE))
                success = false;
        }
    }

    stringBuffer.append("<br/>");
    stringBuffer.append("<ul class=\"nav nav-tabs\" role=\"tablist\">");
    stringBuffer.append(
            "<li role=\"presentation\" class=\"active\"><a href=\"#detail\" aria-controls=\"detail\" role=\"tab\" data-toggle=\"tab\">Steps</a></li>");

    if (DataManager.instance().isArtifactEnabled(ArtifactType.CONSOLE_LOG))
        stringBuffer.append(
                "<li role=\"presentation\"><a href=\"#console\" aria-controls=\"console\" role=\"tab\" data-toggle=\"tab\">Console Log</a></li>");

    if (DataManager.instance().isArtifactEnabled(ArtifactType.WCAG_REPORT))
        stringBuffer.append(
                "<li role=\"presentation\"><a href=\"#wcag\" aria-controls=\"wcag\" role=\"tab\" data-toggle=\"tab\">WCAG Report</a></li>");

    if (!success && DataManager.instance().isArtifactEnabled(ArtifactType.DEVICE_LOG))
        stringBuffer.append(
                "<li role=\"presentation\"><a href=\"#deviceLog\" aria-controls=\"deviceLog\" role=\"tab\" data-toggle=\"tab\">Device Log</a></li>");

    if (DataManager.instance().isArtifactEnabled(ArtifactType.EXECUTION_RECORD_CSV))
        stringBuffer.append("<li role=\"presentation\"><a class=link-tab hRef=\"" + testName
                + ".csv\" class=\"list-group-item\">Execution Record</a></li>");

    stringBuffer.append(
            "<li role=\"presentation\"><a href=\"#external\" aria-controls=\"external\" role=\"tab\" data-toggle=\"tab\">Links</a></li>");

    stringBuffer.append(
            "<span class=\"pull-right text-muted\"><a hRef=\"../../index.html\">Return to Test Execution Summary</a></span></ul>");

    stringBuffer.append("<div class=\"tab-content\">");

    stringBuffer.append("<div role=\"tabpanel\" class=\"tab-pane active\" id=\"detail\">");
    stringBuffer.append(
            "<div class=\"table-responsive table-bordered\"><table class=\"table table-hover table-condensed\">");
    stringBuffer.append(
            "<thead><th width=\"80%\">Steps Performed</th><th width=\"20%\">Started</th><th align=center width=\"0%\">Status</th></thead>");
    if (DeviceManager.instance().getArtifacts(ArtifactType.EXECUTION_RECORD) != null
            && !DeviceManager.instance().getArtifacts(ArtifactType.EXECUTION_RECORD).isEmpty()) {
        for (Object item : DeviceManager.instance().getArtifacts(ArtifactType.EXECUTION_RECORD)) {
            ExecutionRecord eItem = (ExecutionRecord) item;

            //if (( eItem.getDeviceName() != null ) &&
            //    ( device.getDeviceName() != null ) &&
            //    ( !eItem.getDeviceName().equals( device.getDeviceName() )))
            //{
            //    continue;
            // }

            stringBuffer.append(eItem.toHTML(spaceCount));
            spaceCount++;
        }
    }

    stringBuffer.append("</TABLE></div></div>");

    if (DataManager.instance().isArtifactEnabled(ArtifactType.CONSOLE_LOG))
        stringBuffer.append(
                "<div role=\"tabpanel\" class=\"tab-pane\" id=\"console\"><div id=\"list\"><p><iframe src=\"console.txt\" frameborder=\"0\" height=\"100%\" width=\"100%\"></iframe></p></div></div>");

    if (DataManager.instance().isArtifactEnabled(ArtifactType.WCAG_REPORT))
        stringBuffer.append(
                "<div role=\"tabpanel\" class=\"tab-pane\" id=\"wcag\"><div id=\"list\"><p><iframe src=\"wcag.html\" frameborder=\"0\" height=\"100%\" width=\"100%\"></iframe></p></div></div>");

    if (!success && DataManager.instance().isArtifactEnabled(ArtifactType.DEVICE_LOG))
        stringBuffer.append(
                "<div role=\"tabpanel\" class=\"tab-pane\" id=\"deviceLog\"><div id=\"list\"><p><iframe src=\"deviceLog.txt\" frameborder=\"0\" height=\"100%\" width=\"100%\"></iframe></p></div></div>");

    stringBuffer.append("<div role=\"tabpanel\" class=\"tab-pane\" id=\"external\">");
    stringBuffer.append("<div class=\"list-group\">");

    String wtUrl = ((DeviceWebDriver) webDriver).getWindTunnelReport();
    if (cloudProvider.equals("PERFECTO") && wtUrl != null && !wtUrl.isEmpty())
        stringBuffer.append("<a target=_blank hRef=\"" + UriEncoder.encode(wtUrl).replace("%3F", "?")
                + "\" class=\"list-group-item\">Perfecto Single Test Report</a>");

    if (DataManager.instance().isArtifactEnabled(ArtifactType.SAUCE_LABS)) {
        if (cloudProvider.equals("SAUCELABS")) {
            stringBuffer.append("<a target=_blank hRef=\"");
            stringBuffer.append("https://saucelabs.com/beta/tests/")
                    .append(((DeviceWebDriver) webDriver).getExecutionId()).append("/commands#0");
            stringBuffer.append("\" class=\"list-group-item\">SauceLabs Execution Report</a>");
        }
    }

    if (cloudProvider.equals("PERFECTO")
            && DataManager.instance().isArtifactEnabled(ArtifactType.EXECUTION_REPORT_CSV))
        stringBuffer.append(
                "<a target=_blank hRef=\"EXECUTION_REPORT_CSV.csv\" class=\"list-group-item\">Perfecto Execution Report (CSV)</a>");

    if (cloudProvider.equals("PERFECTO")
            && DataManager.instance().isArtifactEnabled(ArtifactType.EXECUTION_REPORT)
            || DataManager.instance().isArtifactEnabled(ArtifactType.EXECUTION_REPORT_PDF))
        stringBuffer.append(
                "<a target=_blank hRef=\"EXECUTION_REPORT_PDF.pdf\" class=\"list-group-item\">Perfecto Execution Report (PDF)</a>");

    if (cloudProvider.equals("PERFECTO")
            && DataManager.instance().isArtifactEnabled(ArtifactType.EXECUTION_REPORT_HTML))
        stringBuffer.append(
                "<a target=_blank hRef=\"EXECUTION_REPORT_HTML.html\" class=\"list-group-item\">Perfecto Execution Report (HTML)</a>");

    if (cloudProvider.equals("PERFECTO")
            && DataManager.instance().isArtifactEnabled(ArtifactType.EXECUTION_REPORT_XML))
        stringBuffer.append(
                "<a target=_blank hRef=\"EXECUTION_REPORT_XML.xml\" class=\"list-group-item\">Perfecto Execution Report (XML)</a>");

    if (((DeviceWebDriver) webDriver).isConnected()) {
        if (cloudProvider.equals("PERFECTO")) {
            if (DataManager.instance().isArtifactEnabled(ArtifactType.REPORTIUM)) {
                if (((ReportiumProvider) webDriver).getReportiumClient() != null) {
                    log.info("REPORTIUM URL: "
                            + ((ReportiumProvider) webDriver).getReportiumClient().getReportUrl());
                    stringBuffer.append("<a target=_blank hRef=\""
                            + ((ReportiumProvider) webDriver).getReportiumClient().getReportUrl()
                            + "\" class=\"list-group-item\">Perfecto Reportium Report</a>");
                }
            }
        }
    }

    stringBuffer.append("</div></div>");

    stringBuffer.append("</div></div></BODY>");
    stringBuffer.append(
            "<script src=\"http://www.xframium.org/output/assets/js/jquery.min.js\"></script><script src=\"http://www.xframium.org/output/assets/js/chart.js\"></script><script src=\"http://www.xframium.org/output/assets/js/tablesorter.min.js\"></script><script src=\"http://www.xframium.org/output/assets/js/toolkit.js\"></script><script src=\"http://www.xframium.org/output/assets/js/application.js\"></script><script>$('.link-tab').click(function() {window.open($(this).attr('href'));});</script>");
    stringBuffer.append("</HTML>");

    return new Artifact(rootFolder + testName + ".html", stringBuffer.toString().getBytes());
}

From source file:edu.emory.cci.aiw.neo4jetl.Neo4jQueryResultsHandlerWrapped.java

@Override
public void finish() throws QueryResultsHandlerProcessingException {
    // add/update a statistics node to save the number of patients added
    if (this.db != null) {
        this.transaction.success();
        this.transaction.close();
        this.transaction = null;

        try (Transaction tx = this.db.beginTx()) {
            if (this.query.getQueryMode() == QueryMode.REPLACE) {
                Schema schema = this.db.schema();
                schema.indexFor(NODE_LABEL).on("__uid").create();
                schema.indexFor(NODE_LABEL).on("__type").create();
                for (IndexOnProperty indexOnProperty : this.configuration.getPropertiesToIndex()) {
                    schema.indexFor(NODE_LABEL).on(indexOnProperty.getPropertyName()).create();
                }//w ww .j a v  a2s  .com
            }

            tx.success();
        }

        if (this.query.getQueryMode() == QueryMode.REPLACE) {
            try (Transaction tx = this.db.beginTx()) {
                Schema schema = this.db.schema();
                schema.awaitIndexesOnline(4, TimeUnit.HOURS);
                tx.success();
            }
        }

        try (Transaction tx = this.db.beginTx()) {
            Node node;
            try {
                node = this.db.findNode(Neo4jStatistics.NODE_LABEL, null, null);
            } catch (MultipleFoundException ex) {
                throw new QueryResultsHandlerProcessingException("duplicate statistics node");
            }
            if (node == null) {
                node = this.db.createNode(Neo4jStatistics.NODE_LABEL);
            }

            ResourceIterator<Node> findNodes = this.db.findNodes(NODE_LABEL, keyType, null);
            int countKeys = IteratorUtil.count(findNodes);

            node.setProperty(Neo4jStatistics.TOTAL_KEYS, countKeys);

            tx.success();
        }

    }
}

From source file:io.druid.segment.realtime.plumber.RealtimePlumberSchoolTest.java

@Test(timeout = 60000)
public void testPersistFails() throws Exception {
    final AtomicBoolean committed = new AtomicBoolean(false);
    plumber.getSinks().put(0L, new Sink(new Interval(0, TimeUnit.HOURS.toMillis(1)), schema, tuningConfig,
            new DateTime("2014-12-01T12:34:56.789").toString()));
    plumber.startJob();//from  ww  w.j  av  a  2 s . c o  m
    final InputRow row = EasyMock.createNiceMock(InputRow.class);
    EasyMock.expect(row.getTimestampFromEpoch()).andReturn(0L);
    EasyMock.expect(row.getDimensions()).andReturn(new ArrayList<String>());
    EasyMock.replay(row);
    plumber.add(row, Committers.supplierOf(Committers.nil()));
    plumber.persist(Committers.supplierFromRunnable(new Runnable() {
        @Override
        public void run() {
            committed.set(true);
            throw new RuntimeException();
        }
    }).get());
    while (!committed.get()) {
        Thread.sleep(100);
    }

    // Exception may need time to propagate
    while (metrics.failedPersists() < 1) {
        Thread.sleep(100);
    }

    Assert.assertEquals(1, metrics.failedPersists());
}

From source file:org.apache.pulsar.client.impl.RawReaderTest.java

@Test
public void testBatchingExtractKeysAndIds() throws Exception {
    String topic = "persistent://my-property/my-ns/my-raw-topic";

    try (Producer<byte[]> producer = pulsarClient.newProducer().topic(topic).maxPendingMessages(3)
            .enableBatching(true).batchingMaxMessages(3).batchingMaxPublishDelay(1, TimeUnit.HOURS)
            .messageRoutingMode(MessageRoutingMode.SinglePartition).create()) {
        producer.newMessage().key("key1").value("my-content-1".getBytes()).sendAsync();
        producer.newMessage().key("key2").value("my-content-2".getBytes()).sendAsync();
        producer.newMessage().key("key3").value("my-content-3".getBytes()).send();
    }//w w  w.  j  a va 2s . c  o  m

    RawReader reader = RawReader.create(pulsarClient, topic, subscription).get();
    try (RawMessage m = reader.readNextAsync().get()) {
        List<ImmutablePair<MessageId, String>> idsAndKeys = RawBatchConverter.extractIdsAndKeys(m);

        Assert.assertEquals(idsAndKeys.size(), 3);

        // assert message ids are in correct order
        Assert.assertTrue(idsAndKeys.get(0).getLeft().compareTo(idsAndKeys.get(1).getLeft()) < 0);
        Assert.assertTrue(idsAndKeys.get(1).getLeft().compareTo(idsAndKeys.get(2).getLeft()) < 0);

        // assert keys are as expected
        Assert.assertEquals(idsAndKeys.get(0).getRight(), "key1");
        Assert.assertEquals(idsAndKeys.get(1).getRight(), "key2");
        Assert.assertEquals(idsAndKeys.get(2).getRight(), "key3");
    } finally {
        reader.closeAsync().get();
    }
}

From source file:com.linkedin.pinot.common.metadata.SegmentZKMetadataTest.java

private ZNRecord getTestInProgressRealtimeSegmentZNRecord() {
    String segmentName = "testTable_R_1000_groupId0_part0";
    ZNRecord record = new ZNRecord(segmentName);
    record.setSimpleField(CommonConstants.Segment.SEGMENT_NAME, segmentName);
    record.setSimpleField(CommonConstants.Segment.TABLE_NAME, "testTable");
    record.setSimpleField(CommonConstants.Segment.INDEX_VERSION, "v1");
    record.setEnumField(CommonConstants.Segment.SEGMENT_TYPE, CommonConstants.Segment.SegmentType.REALTIME);
    record.setEnumField(CommonConstants.Segment.Realtime.STATUS,
            CommonConstants.Segment.Realtime.Status.IN_PROGRESS);
    record.setLongField(CommonConstants.Segment.START_TIME, 1000);
    record.setLongField(CommonConstants.Segment.END_TIME, -1);
    record.setSimpleField(CommonConstants.Segment.TIME_UNIT, TimeUnit.HOURS.toString());
    record.setLongField(CommonConstants.Segment.TOTAL_DOCS, -1);
    record.setLongField(CommonConstants.Segment.CRC, -1);
    record.setLongField(CommonConstants.Segment.CREATION_TIME, 1000);
    record.setIntField(CommonConstants.Segment.FLUSH_THRESHOLD_SIZE, 1234);
    return record;
}

From source file:com.hyperaware.conference.android.fragment.HomeFragment.java

private void updateUpNextCard() {
    ViewGroup time_groups = (ViewGroup) cardUpNext.findViewById(R.id.vg_time_groups);
    time_groups.removeAllViews();//  w  ww.j  av a  2s .com

    final SortedMap<DateRange, List<AgendaItem>> up_next = AgendaItems.upNext(agenda.getItems().values(),
            timeAtUpdate, TimeUnit.DAYS.toMillis(1), TimeUnit.HOURS.toMillis(1));

    if (up_next.size() > 0) {
        populateTimeGroups(up_next, time_groups);
        cardUpNext.setVisibility(View.VISIBLE);
        upNextStartTime = up_next.firstKey().start;
    } else {
        cardUpNext.setVisibility(View.GONE);
    }
}

From source file:org.apache.jackrabbit.oak.plugins.segment.CompactionAndCleanupIT.java

@Test
public void noCleanupOnCompactionMap() throws Exception {
    // 2MB data, 5MB blob
    final int blobSize = 5 * 1024 * 1024;
    final int dataNodes = 10000;

    FileStore fileStore = FileStore.builder(getFileStoreFolder()).withMaxFileSize(1).build();
    final SegmentNodeStore nodeStore = SegmentNodeStore.builder(fileStore).build();
    CompactionStrategy custom = new CompactionStrategy(false, false, CLEAN_OLD, TimeUnit.HOURS.toMillis(1),
            (byte) 0) {
        @Override//from  ww  w.ja v a  2  s .  c  om
        public boolean compacted(@Nonnull Callable<Boolean> setHead) throws Exception {
            return nodeStore.locked(setHead);
        }
    };
    fileStore.setCompactionStrategy(custom);

    // 1a. Create a bunch of data
    NodeBuilder extra = nodeStore.getRoot().builder();
    NodeBuilder content = extra.child("content");
    for (int i = 0; i < dataNodes; i++) {
        NodeBuilder c = content.child("c" + i);
        for (int j = 0; j < 1000; j++) {
            c.setProperty("p" + i, "v" + i);
        }
    }
    nodeStore.merge(extra, EmptyHook.INSTANCE, CommitInfo.EMPTY);

    final long dataSize = fileStore.size();
    log.debug("File store dataSize {}", byteCountToDisplaySize(dataSize));

    try {
        // 1. Create a property with 5 MB blob
        NodeBuilder builder = nodeStore.getRoot().builder();
        builder.setProperty("a1", createBlob(nodeStore, blobSize));
        builder.setProperty("b", "foo");
        nodeStore.merge(builder, EmptyHook.INSTANCE, CommitInfo.EMPTY);

        // 2. Now remove the property
        builder = nodeStore.getRoot().builder();
        builder.removeProperty("a1");
        nodeStore.merge(builder, EmptyHook.INSTANCE, CommitInfo.EMPTY);

        // 3. Compact
        fileStore.maybeCompact(false);

        // 4. Add some more property to flush the current TarWriter
        builder = nodeStore.getRoot().builder();
        builder.setProperty("a2", createBlob(nodeStore, blobSize));
        nodeStore.merge(builder, EmptyHook.INSTANCE, CommitInfo.EMPTY);

        // There should be no SNFE when running cleanup as compaction map segments
        // should be pinned and thus not collected
        fileStore.maybeCompact(false);
        fileStore.cleanup();

        // refresh the ts ref, to simulate a long wait time
        custom.setOlderThan(0);
        TimeUnit.MILLISECONDS.sleep(5);

        boolean needsCompaction = true;
        for (int i = 0; i < 3 && needsCompaction; i++) {
            needsCompaction = fileStore.maybeCompact(false);
            fileStore.cleanup();
        }
    } finally {
        fileStore.close();
    }
}

From source file:com.atlassian.jira.user.util.UserUtilImpl.java

public UserUtilImpl(final IssueSecurityLevelManager issueSecurityLevelManager,
        final GlobalPermissionManager globalPermissionManager, final CrowdService crowdService,
        DirectoryManager directoryManager, final PermissionManager permissionManager,
        final ApplicationProperties applicationProperties, final SearchProvider searchProvider,
        final ProjectManager projectManager, final ProjectRoleService projectRoleService,
        final ProjectComponentManager componentManager, final SubscriptionManager subscriptionManager,
        final NotificationSchemeManager notificationSchemeManager, final UserHistoryManager userHistoryManager,
        final UserManager userManager, final EventPublisher eventPublisher, final StudioHooks hooks,
        final CacheManager cacheManager) {
    this.directoryManager = directoryManager;
    this.eventPublisher = eventPublisher;
    this.issueSecurityLevelManager = issueSecurityLevelManager;
    this.globalPermissionManager = globalPermissionManager;
    this.permissionManager = permissionManager;
    this.applicationProperties = applicationProperties;
    this.searchProvider = searchProvider;
    this.projectManager = projectManager;
    this.projectRoleService = projectRoleService;
    this.componentManager = componentManager;
    this.subscriptionManager = subscriptionManager;
    this.notificationSchemeManager = notificationSchemeManager;
    this.userHistoryManager = userHistoryManager;
    this.userManager = userManager;

    this.crowdService = crowdService;
    this.hooks = hooks;
    activeUsersCount = cacheManager.getCache(UserUtilImpl.class.getName() + ".activeUsersCount",
            new ActiveUserCountLoader(),
            new CacheSettingsBuilder().expireAfterWrite(2, TimeUnit.HOURS).build());
}