Skip to content

Commit

Permalink
Bugfix for npe (#120)
Browse files Browse the repository at this point in the history
  • Loading branch information
straybirdzls authored and QilongZhang committed Nov 12, 2018
1 parent 677cf5c commit 9172e40
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,10 @@ public static AsyncCommonDigestAppenderManager getSofaTracerDigestReporterAsyncM
if (asyncCommonDigestAppenderManager == null) {
synchronized (SofaTracerDigestReporterAsyncManager.class) {
if (asyncCommonDigestAppenderManager == null) {
asyncCommonDigestAppenderManager = new AsyncCommonDigestAppenderManager(1024);
asyncCommonDigestAppenderManager.start("NetworkAppender");
AsyncCommonDigestAppenderManager localManager = new AsyncCommonDigestAppenderManager(
1024);
localManager.start("NetworkAppender");
asyncCommonDigestAppenderManager = localManager;
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,9 @@ public static SofaTracerStatisticReporterManager getSofaTracerStatisticReporterM
if (existedManager == null) {
synchronized (cycleTimesManager) {
if (cycleTimesManager.get(cycleTime) == null) {
existedManager = new SofaTracerStatisticReporterManager(cycleTime);
cycleTimesManager.put(cycleTime, existedManager);
cycleTimesManager.put(cycleTime, new SofaTracerStatisticReporterManager(
cycleTime));
existedManager = cycleTimesManager.get(cycleTime);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alipay.common.tracer.core.reporter.digest;

import com.alipay.common.tracer.core.appender.manager.AsyncCommonDigestAppenderManager;
import com.alipay.common.tracer.core.reporter.digest.manager.SofaTracerDigestReporterAsyncManager;
import com.alipay.common.tracer.core.span.SofaTracerSpan;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;

import java.util.concurrent.CountDownLatch;
import java.util.concurrent.Executors;
import java.util.concurrent.atomic.AtomicInteger;

import static org.mockito.Mockito.mock;

/**
*
* @author abby.zh
* @version $Id: SofaTracerDigestReporterAsyncManagerTest.java, v 0.1 2018/11/12 4:55 PM abby.zh Exp $
* @since 3.0.1
*/
public class SofaTracerDigestReporterAsyncManagerTest {

private SofaTracerSpan sofaTracerSpan;

@Before
public void before() {
this.sofaTracerSpan = mock(SofaTracerSpan.class);
}

@Test
public void testGetSofaTracerDigestReporterAsyncManager() throws Exception{
AtomicInteger npeCount = new AtomicInteger();
AtomicInteger successCount = new AtomicInteger();
int testTimes = 1000;
int threadCount = 100;
CountDownLatch latch = new CountDownLatch(testTimes);
for (int times = 0 ; times < testTimes; times ++) {
Executors.newFixedThreadPool(threadCount).execute(() -> {
try {
AsyncCommonDigestAppenderManager sofaTracerDigestReporterAsyncManager =
SofaTracerDigestReporterAsyncManager.getSofaTracerDigestReporterAsyncManager();
sofaTracerDigestReporterAsyncManager.append(sofaTracerSpan);
successCount.getAndIncrement();
}catch (NullPointerException e){
npeCount.getAndIncrement();
}finally {
latch.countDown();
}
});
}
latch.await();
Assert.assertEquals(0, npeCount.get());
Assert.assertEquals(testTimes, successCount.get());
}
}

0 comments on commit 9172e40

Please sign in to comment.