Skip to content

Commit

Permalink
Replaced use of System.out.println() in unit tests (#260)
Browse files Browse the repository at this point in the history
  • Loading branch information
merlimat authored Mar 1, 2017
1 parent 24c7724 commit 619ad64
Show file tree
Hide file tree
Showing 12 changed files with 47 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1898,8 +1898,7 @@ public void testActiveDeactiveCursorWithDiscardEntriesFromCache() throws Excepti
cursor2.markDelete((entries2.get(entries2.size() - 1)).getPosition());

// (3) Validate: cache should remove all entries read by both active cursors
System.out.println(
"expected, found :" + (5 * (totalInsertedEntries - readEntries)) + ", " + entryCache.getSize());
log.info("expected, found : {}, {}", (5 * (totalInsertedEntries - readEntries)), entryCache.getSize());
assertEquals((5 * (totalInsertedEntries - readEntries)), entryCache.getSize());

final int remainingEntries = totalInsertedEntries - readEntries;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -280,18 +280,18 @@ public void testPrimarySecondary() throws Exception {

LocalZooKeeperCache originalLZK1 = (LocalZooKeeperCache) zkCacheField.get(pulsar1);
LocalZooKeeperCache originalLZK2 = (LocalZooKeeperCache) zkCacheField.get(pulsar2);
System.out.println("lzk are " + originalLZK1.getChildren(SimpleLoadManagerImpl.LOADBALANCE_BROKERS_ROOT)
+ " 2: " + originalLZK2.getChildren(SimpleLoadManagerImpl.LOADBALANCE_BROKERS_ROOT));
log.info("lzk are {} 2: {}", originalLZK1.getChildren(SimpleLoadManagerImpl.LOADBALANCE_BROKERS_ROOT),
originalLZK2.getChildren(SimpleLoadManagerImpl.LOADBALANCE_BROKERS_ROOT));
zkCacheField.set(pulsar1, mockCache);

LocalZooKeeperCache newZk = (LocalZooKeeperCache) pulsar1.getLocalZkCache();
System.out.println("lzk mocked are " + newZk.getChildren(SimpleLoadManagerImpl.LOADBALANCE_BROKERS_ROOT));
log.info("lzk mocked are {}", newZk.getChildren(SimpleLoadManagerImpl.LOADBALANCE_BROKERS_ROOT));

ZooKeeperChildrenCache availableActiveBrokers = new ZooKeeperChildrenCache(pulsar1.getLocalZkCache(),
SimpleLoadManagerImpl.LOADBALANCE_BROKERS_ROOT);

System.out.println("lzk mocked active brokers are "
+ availableActiveBrokers.get(SimpleLoadManagerImpl.LOADBALANCE_BROKERS_ROOT));
log.info("lzk mocked active brokers are {}",
availableActiveBrokers.get(SimpleLoadManagerImpl.LOADBALANCE_BROKERS_ROOT));

LoadManager loadManager = new SimpleLoadManagerImpl(pulsar1);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@
import org.apache.zookeeper.data.Stat;
import org.mockito.invocation.InvocationOnMock;
import org.mockito.stubbing.Answer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.testng.Assert;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
Expand Down Expand Up @@ -126,7 +128,7 @@ public void testSplitAndOwnBundles() throws Exception {
Policies policies = ObjectMapperFactory.getThreadLocal().readValue(content, Policies.class);
NamespaceBundles localZkBundles = bundleFactory.getBundles(nsname, policies.bundles);
assertTrue(updatedNsBundles.equals(localZkBundles));
System.out.println(policies);
log.info("Policies: {}", policies);

// (3) validate ownership of new split bundles by local owner
bundleList.stream().forEach(b -> {
Expand Down Expand Up @@ -287,4 +289,6 @@ private Pair<NamespaceBundles, List<NamespaceBundle>> splitBundles(NamespaceBund
CompletableFuture.completedFuture(bundles));
return utilityFactory.splitBundles(targetBundle, 2);
}

private static final Logger log = LoggerFactory.getLogger(NamespaceServiceTest.class);
}
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ public void run() {
barrier.await();
// assertTrue(topic.unsubscribe(successSubName).isDone());
Thread.sleep(5, 0);
System.out.println("deleter outcome is " + topic.delete().get());
log.info("deleter outcome is {}", topic.delete().get());
} catch (Exception e) {
e.printStackTrace();
gotException.set(true);
Expand All @@ -146,7 +146,7 @@ public void run() {
ConcurrentOpenHashMap<String, PersistentSubscription> subscriptions = topic.getSubscriptions();
PersistentSubscription ps = subscriptions.get(successSubName);
// Thread.sleep(2,0);
System.out.println("unsubscriber outcome is " + ps.doUnsubscribe(ps.getConsumers().get(0)).get());
log.info("unsubscriber outcome is {}", ps.doUnsubscribe(ps.getConsumers().get(0)).get());
// assertFalse(ps.delete().isCompletedExceptionally());
} catch (Exception e) {
e.printStackTrace();
Expand Down Expand Up @@ -186,11 +186,11 @@ public void run() {
barrier.await();
// assertTrue(topic.unsubscribe(successSubName).isDone());
// Thread.sleep(5,0);
System.out.println(Thread.currentThread() + " forcing topic GC ");
log.info("{} forcing topic GC ", Thread.currentThread());
for (int i = 0; i < 2000; i++) {
topic.checkGC(0);
}
System.out.println("GC done..");
log.info("GC done..");
} catch (Exception e) {
e.printStackTrace();
gotException.set(true);
Expand All @@ -208,7 +208,7 @@ public void run() {
ConcurrentOpenHashMap<String, PersistentSubscription> subscriptions = topic.getSubscriptions();
PersistentSubscription ps = subscriptions.get(successSubName);
// Thread.sleep(2,0);
System.out.println("unsubscriber outcome is " + ps.doUnsubscribe(ps.getConsumers().get(0)).get());
log.info("unsubscriber outcome is {}", ps.doUnsubscribe(ps.getConsumers().get(0)).get());
// assertFalse(ps.delete().isCompletedExceptionally());
} catch (Exception e) {
e.printStackTrace();
Expand Down Expand Up @@ -247,7 +247,7 @@ public void run() {
try {
barrier.await();
Thread.sleep(4, 700);
System.out.println("deleter outcome is " + topic.delete().get());
log.info("deleter outcome is {}", topic.delete().get());
} catch (Exception e) {
e.printStackTrace();
gotException.set(true);
Expand All @@ -265,8 +265,8 @@ public void run() {
// assertTrue(topic.unsubscribe(successSubName).isDone());
ConcurrentOpenHashMap<String, PersistentSubscription> subscriptions = topic.getSubscriptions();
PersistentSubscription ps = subscriptions.get(successSubName);
System.out.println("unsubscribe result : " + topic.unsubscribe(successSubName).get());
System.out.println("closing consumer..");
log.info("unsubscribe result : {}", topic.unsubscribe(successSubName).get());
log.info("closing consumer..");
ps.getConsumers().get(0).close();
} catch (Exception e) {
e.printStackTrace();
Expand Down Expand Up @@ -325,10 +325,7 @@ public void run() {
// assertTrue(topic.unsubscribe(successSubName).isDone());
ConcurrentOpenHashMap<String, PersistentSubscription> subscriptions = topic.getSubscriptions();
PersistentSubscription ps = subscriptions.get(successSubName);
// System.out.println("unsubscribe result : " + topic.unsubscribe(successSubName).get());
log.info("unsubscribe result : " + ps.doUnsubscribe(ps.getConsumers().get(0)).get());
// System.out.println("closing consumer..");
// ps.getConsumers().get(0).close();
} catch (Exception e) {
e.printStackTrace();
gotException.set(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -535,7 +535,7 @@ public void run() {
barrier.await();
// assertTrue(topic.unsubscribe(successSubName).isDone());
Thread.sleep(5, 0);
System.out.println("deleter outcome is " + topic.delete().get());
log.info("deleter outcome is {}", topic.delete().get());
} catch (Exception e) {
e.printStackTrace();
gotException.set(true);
Expand All @@ -554,7 +554,7 @@ public void run() {
ConcurrentOpenHashMap<String, PersistentSubscription> subscriptions = topic.getSubscriptions();
PersistentSubscription ps = subscriptions.get(successSubName);
// Thread.sleep(5,0);
System.out.println("unsubscriber outcome is " + ps.doUnsubscribe(ps.getConsumers().get(0)).get());
log.info("unsubscriber outcome is {}", ps.doUnsubscribe(ps.getConsumers().get(0)).get());
// assertFalse(ps.delete().isCompletedExceptionally());
} catch (Exception e) {
e.printStackTrace();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.InetAddress;
import java.net.URL;
import java.security.KeyStore;
import java.security.PrivateKey;
Expand All @@ -40,6 +39,8 @@

import org.apache.bookkeeper.test.PortManager;
import org.apache.zookeeper.CreateMode;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.testng.Assert;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.Test;
Expand Down Expand Up @@ -259,7 +260,7 @@ private String makeHttpRequest(boolean useTls, boolean useAuth) throws Exception
response = new URL(BROKER_LOOKUP_URL).openStream();
}
String resp = CharStreams.toString(new InputStreamReader(response));
System.out.println(resp);
log.info("Response: {}", resp);
return resp;
} finally {
Closeables.close(response, false);
Expand Down Expand Up @@ -337,4 +338,6 @@ void teardown() throws Exception {
Assert.fail("Got exception while closing the pulsar instance ", e);
}
}

private static final Logger log = LoggerFactory.getLogger(WebServiceTest.class);
}
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@ public void testAsyncPartitionedProducerConsumer() throws Exception {
producer.send(message.getBytes());
}

System.out.println(" start receiving messages :");
log.info(" start receiving messages :");

// receive messages
CountDownLatch latch = new CountDownLatch(totalMsg);
Expand Down Expand Up @@ -428,7 +428,7 @@ public void testAsyncPartitionedProducerConsumerQueueSizeOne() throws Exception
producer.send(message.getBytes());
}

System.out.println(" start receiving messages :");
log.info(" start receiving messages :");

// receive messages
CountDownLatch latch = new CountDownLatch(totalMsg);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -781,7 +781,7 @@ public void testAsyncProducerAndConsumer() throws Exception {
produceMsgs.add(message);
}

System.out.println(" start receiving messages :");
log.info(" start receiving messages :");
CountDownLatch latch = new CountDownLatch(totalMsg);
// receive messages
ExecutorService executor = Executors.newFixedThreadPool(1);
Expand Down Expand Up @@ -822,7 +822,7 @@ public void testAsyncProducerAndConsumerWithZeroQueueSize() throws Exception {
produceMsgs.add(message);
}

System.out.println(" start receiving messages :");
log.info(" start receiving messages :");
CountDownLatch latch = new CountDownLatch(totalMsg);
// receive messages
ExecutorService executor = Executors.newFixedThreadPool(1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -368,12 +368,12 @@ public void testResetCursor(SubscriptionType subType) throws Exception {
}
consumer.acknowledge(msg);
long publishTime = ((MessageImpl) msg).getPublishTime();
System.out.println(" publish time is " + publishTime + "," + msg.getMessageId());
log.info(" publish time is " + publishTime + "," + msg.getMessageId());
TimestampEntryCount timestampEntryCount = publishTimeIdMap.computeIfAbsent(publishTime,
(k) -> new TimestampEntryCount(publishTime));
timestampEntryCount.incrementAndGet();
} catch (final PulsarClientException e) {
System.out.println("Failed to ack!");
log.warn("Failed to ack!");
}
});

Expand All @@ -400,7 +400,7 @@ public void testResetCursor(SubscriptionType subType) throws Exception {
received.clear();

// publish testSize num of msgs
System.out.println("Sending more messages.");
log.info("Sending more messages.");
for (Integer n = 0; n < testSize; n++) {
producer.send(msgBytes);
Thread.sleep(1);
Expand All @@ -421,7 +421,7 @@ public void testResetCursor(SubscriptionType subType) throws Exception {
received.clear();

log.info("reset cursor to " + timestamp + " for topic " + destName.toString() + " for subs " + subsId);
System.out.println("issuing admin operation on " + admin.getServiceUrl().toString());
log.info("issuing admin operation on " + admin.getServiceUrl().toString());
List<String> subList = admin.persistentTopics().getSubscriptions(destName.toString());
for (String subs : subList) {
log.info("got sub " + subs);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
import java.util.concurrent.CompletableFuture;

import org.apache.commons.lang3.tuple.Pair;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.testng.annotations.Test;

import com.github.benmanes.caffeine.cache.AsyncLoadingCache;
Expand Down Expand Up @@ -269,7 +271,8 @@ private void assertBundleDivideInTwo(NamespaceBundle bundle, List<NamespaceBundl
String uRange = String.format("0x%08x_0x%08x", middle, upper);
assertTrue(bundles.get(0).getBundleRange().equals(lRange));
assertTrue(bundles.get(1).getBundleRange().equals(uRange));
System.out.println(String.format("[%s,%s] => [%s,%s]", range[0], range[1], lRange, uRange));

log.info("[{},{}] => [{},{}]", range[0], range[1], lRange, uRange);
}

private static final Logger log = LoggerFactory.getLogger(NamespaceBundlesTest.class);
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
import javax.ws.rs.ClientErrorException;
import javax.ws.rs.ServerErrorException;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.testng.annotations.Test;

import com.yahoo.pulsar.client.admin.PulsarAdmin;
Expand All @@ -40,7 +42,8 @@ public class PulsarBrokerStatsClientTest {
@Test
public void testServiceException() throws Exception {
URL url = new URL("http://localhost:15000");
BrokerStatsImpl client = (BrokerStatsImpl) spy(new PulsarAdmin(url, (Authentication) null).brokerStats());
PulsarAdmin admin = new PulsarAdmin(url, (Authentication) null);
BrokerStatsImpl client = (BrokerStatsImpl) spy(admin.brokerStats());
try {
client.getLoadReport();
} catch (PulsarAdminException e) {
Expand All @@ -64,7 +67,10 @@ public void testServiceException() throws Exception {
assertTrue(client.getApiException(new ServerErrorException(500)) instanceof ServerSideErrorException);
assertTrue(client.getApiException(new ServerErrorException(503)) instanceof PulsarAdminException);

System.out.println(client);
log.info("Client: ", client);

admin.close();
}

private static final Logger log = LoggerFactory.getLogger(PulsarBrokerStatsClientTest.class);
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ public class BackoffTest {
@Test
public void shouldBackoffTest() {
long currentTimestamp = System.nanoTime();
System.out.println(currentTimestamp);
Backoff testBackoff = new Backoff(currentTimestamp, TimeUnit.NANOSECONDS, 100, TimeUnit.MICROSECONDS);
// gives false
Assert.assertTrue(!testBackoff.shouldBackoff(0L, TimeUnit.NANOSECONDS, 0));
Expand Down

0 comments on commit 619ad64

Please sign in to comment.