Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

W 17464266.code coverage #1019

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/gradle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
if: ${{ !contains(github.ref, 'dependabot') }}
run: echo "${{ secrets.SALESFORCE_DOCKER_HUB_SECRET }}" | docker login --username sholavanalli508 --password-stdin
- name: Build with Gradle
run: ./gradlew build --info --stacktrace
run: ./gradlew build printCoverageReport --info --stacktrace
- name: Publish Failure Test Report
if: ${{ failure() }} # doesn't run unless it specifically grabs the failure condition of the previous step..
uses: scacap/action-surefire-report@v1
Expand Down
4 changes: 2 additions & 2 deletions carbonj.service/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ RUN yum update -y && \
yum install -y gcc-c++ gcc make libtool automake autoconf make python3-devel && \
rpm --import http://repos.azulsystems.com/RPM-GPG-KEY-azulsystems && \
yum install -y https://cdn.azul.com/zulu/bin/zulu-repo-1.0.0-1.noarch.rpm && \
yum install -y https://mirror.stream.centos.org/9-stream/AppStream/$(uname -m)/os/Packages/pcp-conf-6.2.1-1.el9.$(uname -m).rpm && \
yum install -y https://mirror.stream.centos.org/9-stream/AppStream/$(uname -m)/os/Packages/pcp-libs-6.2.1-1.el9.$(uname -m).rpm && \
yum install -y https://mirror.stream.centos.org/9-stream/AppStream/$(uname -m)/os/Packages/pcp-conf-6.2.2-6.el9.$(uname -m).rpm && \
yum install -y https://mirror.stream.centos.org/9-stream/AppStream/$(uname -m)/os/Packages/pcp-libs-6.2.2-6.el9.$(uname -m).rpm && \
#
# If sysstat version is updated, confirm iolog.sh execution and update associated version check in entrypoint.sh
#
Expand Down
21 changes: 21 additions & 0 deletions carbonj.service/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ task licenseCheckDockerFiles(type: com.hierynomus.gradle.license.tasks.LicenseFo
licenseMain.dependsOn licenseCheckDockerFiles

apply plugin: 'java'
apply plugin: 'jacoco'
apply plugin: 'eclipse'
apply plugin: 'idea'
apply plugin: 'io.spring.dependency-management'
Expand Down Expand Up @@ -236,6 +237,26 @@ test {
environment "AWS_REGION", "us-east-1"
}

jacocoTestReport {
reports {
html.required = true
xml.required = true
csv.required = true
}
}

task printCoverageReport {
dependsOn jacocoTestReport
doLast {
def reportFile = file("${projectDir}/build/reports/jacoco/test/jacocoTestReport.csv")
if (reportFile.exists()) {
println reportFile.text
} else {
println "Coverage report not found!"
}
}
}

tasks.withType(Test) {
testLogging {
// set options for log level LIFECYCLE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,6 @@
*/
package com.demandware.carbonj.service.db.model;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Optional;

import com.demandware.carbonj.service.accumulator.MetricAggregationPolicy;
import com.google.common.base.Preconditions;

import com.demandware.carbonj.service.strings.StringsCache;

public class MsgPackMetric
{
final public String path;
Expand All @@ -26,4 +16,4 @@ public MsgPackMetric( Metric metric )
this.path = metric.name;
this.isLeaf = metric.isLeaf();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
package com.demandware.carbonj.service.db.model;

import java.util.List;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonCreator;

Expand All @@ -32,12 +31,7 @@ public class MsgPackSeries

public MsgPackSeries( Series series)
{
this.start = series.start;
this.end = series.end;
this.step = series.step;
this.name = series.name;
this.pathExpression = series.name;
this.values = series.values;
this(series.start, series.end, series.step, series.name, series.name, series.values);
}

@JsonCreator
Expand Down Expand Up @@ -66,4 +60,4 @@ public String toString()
", values=" + values +
'}';
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.stream.Collectors;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand All @@ -26,9 +25,9 @@ public class StorageAggregationPolicySource
private static final Logger log = LoggerFactory.getLogger( StorageAggregationPolicySource.class );

// reuse same instance across multiple metrics.
private CopyOnWriteArrayList<AggregationPolicy> policies = new CopyOnWriteArrayList<>( );
private final CopyOnWriteArrayList<AggregationPolicy> policies = new CopyOnWriteArrayList<>( );

private StorageAggregationRulesLoader rulesLoader;
private final StorageAggregationRulesLoader rulesLoader;

public StorageAggregationPolicySource( StorageAggregationRulesLoader rulesLoader)
{
Expand Down Expand Up @@ -75,15 +74,11 @@ public synchronized void cleanup()
{
log.info("checking for obsolete aggregation policies to remove from cache");
List<AggregationPolicy> obsolete = policies.stream()
.filter( p -> p.configChanged() )
.collect( Collectors.toList());
.filter(AggregationPolicy::configChanged)
.toList();
// no need to keep policies that represent obsolete config.
policies.removeAll( obsolete );
log.info("purged obsolete aggregation policies from cache. Number of obsolete policies found: "
+ obsolete.size() + ", total number of policies after purge: " + policies.size());
}

public StorageAggregationRulesLoader getRulesLoader() {
return rulesLoader;
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import com.codahale.metrics.MetricRegistry;
import com.demandware.carbonj.service.engine.DataPoint;
import com.google.common.base.Preconditions;
import com.google.common.base.Throwables;
import com.google.common.io.Closeables;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
Expand All @@ -28,7 +27,7 @@ public class LineProtocolDestinationSocket
extends Destination
implements LineProtocolDestination
{
private static Logger log = LoggerFactory.getLogger( LineProtocolDestinationSocket.class );
private static final Logger log = LoggerFactory.getLogger( LineProtocolDestinationSocket.class );

private final MetricRegistry metricRegistry;
final String ip;
Expand Down Expand Up @@ -126,7 +125,7 @@ void close()
}
catch ( InterruptedException e )
{
throw Throwables.propagate( e );
throw new RuntimeException(e);
}
}

Expand Down Expand Up @@ -199,25 +198,24 @@ public Number getValue()
{
Closeables.close( pw, true );
}
catch ( IOException e2 )
{
catch ( IOException ignored) {
}
pw = null;
try
{
Closeables.close( sock, true );
}
catch ( IOException e2 )
{
catch ( IOException ignored) {
}
sock = null;
try
{
//noinspection BusyWait
Thread.sleep( 1000 ); // try reconnect in a sec
}
catch ( InterruptedException e1 )
{
throw Throwables.propagate( e );
throw new RuntimeException(e1);
}
}
finally
Expand All @@ -236,8 +234,7 @@ public Number getValue()
{
Closeables.close( sock, true );
}
catch ( IOException e )
{
catch ( IOException ignored) {
}
metricRegistry.remove(name);
log.info("Exited " + name);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,17 +46,15 @@ public class InputQueue<T> extends Thread implements Consumer<T>, StatsAware, Cl

private final QueueProcessor<T> pointProcessor;

private int batchSize;
private final int batchSize;

private BlockingQueue<T> queue;
private final BlockingQueue<T> queue;

private volatile boolean stop = false;

private long emptyQueuePauseMillis;
private final long emptyQueuePauseMillis;

private RejectionHandler rh;

private final int queueCapacity;
private final RejectionHandler<T> rh;

public InputQueue(MetricRegistry metricRegistry, String name, QueueProcessor<T> queueProcessor, int queueSize,
RejectionHandler<T> rejectionHandler, int batchSize,
Expand All @@ -65,7 +63,6 @@ public InputQueue(MetricRegistry metricRegistry, String name, QueueProcessor<T>
this.pointProcessor = Preconditions.checkNotNull(queueProcessor);
this.batchSize = batchSize;
this.emptyQueuePauseMillis = emptyQueuePauseMillis;
this.queueCapacity = queueSize;
this.queue = new ArrayBlockingQueue<>( queueSize );
this.rh = rejectionHandler;

Expand Down Expand Up @@ -100,13 +97,6 @@ public void drain()
@Override
public void run()
{

if ( queue == null )
{
stop = true;
return;
}

// queue consumer loop.
while ( true )
{
Expand Down Expand Up @@ -202,19 +192,7 @@ public void refreshStats()

public int queuedItemsCount()
{
if ( queue == null )
{
return 0;
}
else
{
return queue.size();
}
}

public int queueCapacity()
{
return queueCapacity;
return queue.size();
}

private String queueSizeGaugeName(String name)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/**
* Copyright (c) 2018, salesforce.com, inc.
* All rights reserved.
* SPDX-License-Identifier: BSD-3-Clause
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/BSD-3-Clause
*/
package com.demandware.carbonj.service.accumulator;

import com.demandware.carbonj.service.engine.DataPoint;

import java.util.concurrent.atomic.AtomicInteger;

public class CountingLatePointLogger implements LatePointLogger {

private final AtomicInteger latePoints;

public CountingLatePointLogger(AtomicInteger latePoints) {
this.latePoints = latePoints;
}

@Override
public void logLatePoint(DataPoint m, long now, Reason r, String context) {
latePoints.incrementAndGet();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/**
* Copyright (c) 2018, salesforce.com, inc.
* All rights reserved.
* SPDX-License-Identifier: BSD-3-Clause
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/BSD-3-Clause
*/
package com.demandware.carbonj.service.accumulator;

import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.*;

public class TestAggregateFunction {
@Test
public void testAggregateFunction() {
AggregateFunction aggregateFunction = AggregateFunction.create("foo.bar.p95", MetricAggregationMethod.CUSTOM1);
assertInstanceOf(AggregateFunction.AvgAggregateFunction.class, aggregateFunction);
assertEquals(0, aggregateFunction.apply());
try {
aggregateFunction.getValues();
fail("Should have thrown an exception");
} catch (UnsupportedOperationException e) {
}
aggregateFunction = AggregateFunction.create("foo.bar.latency", MetricAggregationMethod.LATENCY);
assertInstanceOf(AggregateFunction.LatencyAggregateFunction.class, aggregateFunction);
assertEquals(0, aggregateFunction.apply());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/**
* Copyright (c) 2018, salesforce.com, inc.
* All rights reserved.
* SPDX-License-Identifier: BSD-3-Clause
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/BSD-3-Clause
*/
package com.demandware.carbonj.service.accumulator;

import com.codahale.metrics.MetricRegistry;
import com.demandware.carbonj.service.engine.DataPoint;
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertEquals;

public class TestLatePointLoggerImpl {
@Test
public void test() {
MetricRegistry metricRegistry = new MetricRegistry();
LatePointLoggerImpl latePointLogger = new LatePointLoggerImpl(metricRegistry);
latePointLogger.logLatePoint(new DataPoint("foo.bar", 123, 60), 120, LatePointLogger.Reason.SLOT_CLOSED, "Context");
assertEquals(1, metricRegistry.getCounters().get("aggregator.skippedDelayed").getCount());
assertEquals(60, metricRegistry.getHistograms().get("aggregator.pointAgeHistogram").getSnapshot().get95thPercentile());
}
}
Loading
Loading