HIGUCHI Yuta
Committed by Ray Milkey

Implement toString()

- add more debug logs

Change-Id: I1541d66f24d2dde0712a4daef081ca1f49951ef8
......@@ -25,6 +25,7 @@ import org.slf4j.LoggerFactory;
import com.fasterxml.jackson.databind.JsonNode;
import com.google.common.annotations.Beta;
import com.google.common.base.MoreObjects;
/**
* Configuration to specify maximum available bandwidth resource (Capacity) on a port.
......@@ -82,4 +83,11 @@ public class BandwidthCapacity extends Config<ConnectPoint> {
return Bandwidth.mbps(v.asDouble());
}
}
@Override
public String toString() {
return MoreObjects.toStringHelper(this)
.add("capacity", capacity())
.toString();
}
}
......
......@@ -16,6 +16,7 @@
package org.onosproject.store.primitives;
import java.util.Collection;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
import java.util.function.BiConsumer;
......@@ -149,6 +150,23 @@ public final class ConsistentMapBackedJavaMap<K, V> implements Map<K, V> {
}
@Override
public String toString() {
// Map like output
StringBuilder sb = new StringBuilder();
sb.append('{');
Iterator<Entry<K, Versioned<V>>> it = backingMap.entrySet().iterator();
while (it.hasNext()) {
Entry<K, Versioned<V>> entry = it.next();
sb.append(entry.getKey()).append('=').append(entry.getValue().value());
if (it.hasNext()) {
sb.append(',').append(' ');
}
}
sb.append('}');
return sb.toString();
}
@Override
public void forEach(BiConsumer<? super K, ? super V> action) {
entrySet().forEach(e -> action.accept(e.getKey(), e.getValue()));
}
......
......@@ -505,11 +505,13 @@ public class ConsistentResourceStore extends AbstractStore<ResourceEvent, Resour
private <K, V> boolean removeValues(TransactionalMap<K, Set<V>> map, K key, List<? extends V> values) {
Set<V> oldValues = map.putIfAbsent(key, new LinkedHashSet<>());
if (oldValues == null) {
log.trace("No-Op removing values. key {} did not exist", key);
return true;
}
if (values.stream().allMatch(x -> !oldValues.contains(x))) {
// don't write map because none of the values are stored
log.trace("No-Op removing values. key {} did not contain {}", key, values);
return true;
}
......
......@@ -189,6 +189,11 @@ public class DefaultConsistentMap<K, V> extends Synchronous<AsyncConsistentMap<K
return javaMap;
}
@Override
public String toString() {
return asJavaMap().toString();
}
private static <T> T complete(CompletableFuture<T> future) {
try {
return future.get(OPERATION_TIMEOUT_MILLIS, TimeUnit.MILLISECONDS);
......
......@@ -29,6 +29,8 @@ import org.onosproject.store.service.Transaction;
import org.onosproject.store.service.TransactionContext;
import org.onosproject.store.service.TransactionalMap;
import com.google.common.base.MoreObjects;
import com.google.common.base.MoreObjects.ToStringHelper;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.google.common.util.concurrent.Futures;
......@@ -114,4 +116,16 @@ public class DefaultTransactionContext implements TransactionContext {
}
}
}
@Override
public String toString() {
ToStringHelper s = MoreObjects.toStringHelper(this)
.add("transactionId", transactionId)
.add("isOpen", isOpen);
txMaps.entrySet().forEach(e -> {
s.add(e.getKey(), e.getValue());
});
return s.toString();
}
}
......
......@@ -30,6 +30,7 @@ import org.onosproject.store.service.Versioned;
import static com.google.common.base.Preconditions.*;
import com.google.common.base.MoreObjects;
import com.google.common.base.Objects;
import com.google.common.cache.CacheBuilder;
import com.google.common.cache.CacheLoader;
......@@ -193,6 +194,15 @@ public class DefaultTransactionalMap<K, V> implements TransactionalMap<K, V> {
return updates;
}
// TODO: build expected result Map processing DB updates?
@Override
public String toString() {
return MoreObjects.toStringHelper(this)
.add("backingMap", backingMap)
.add("updates", prepareDatabaseUpdates())
.toString();
}
/**
* Discards all changes made to this transactional map.
*/
......