Add a set of unit tests for openstack telemetry app

Change-Id: Ib5963c61ef0c0302a90a4f30d3dd1f0ec2862aea
This commit is contained in:
Jian Li 2018-07-30 11:55:44 +09:00
parent cc9620aee7
commit ae3fcfffa2
26 changed files with 814 additions and 17 deletions

View File

@ -75,7 +75,7 @@ public class DefaultInstancePortTest {
private InstancePort instancePort2;
/**
* Checks that the DefaultInstancePort class is immutable.
* Tests class immutability.
*/
@Test
public void testImmutability() {

View File

@ -58,6 +58,9 @@ public class DefaultOpenstackAuthTest {
.build();
}
/**
* Tests object equality.
*/
@Test
public void testEquality() {
new EqualsTester().addEqualityGroup(OS_AUTH_1, OS_AUTH_3)
@ -65,6 +68,9 @@ public class DefaultOpenstackAuthTest {
.testEquals();
}
/**
* Test object construction.
*/
@Test
public void testConstruction() {
OpenstackAuth auth = OS_AUTH_1;

View File

@ -43,4 +43,11 @@ public interface OpenstackTelemetryService {
* @param flowInfos virtual flow information
*/
void publish(Set<FlowInfo> flowInfos);
/**
* Obtains a collection of openstack telemetry services.
*
* @return telemetry services
*/
Set<TelemetryService> telemetryServices();
}

View File

@ -17,6 +17,9 @@ package org.onosproject.openstacktelemetry.api;
import org.onosproject.openstacktelemetry.api.config.TelemetryConfig;
/**
* Telemetry configuration service interface.
*/
public interface TelemetryConfigService {
/**

View File

@ -204,6 +204,15 @@ public final class DefaultFlowInfo implements FlowInfo {
.toString();
}
/**
* Obtains a default flow info builder object.
*
* @return flow info builder object
*/
public static Builder builder() {
return new DefaultBuilder();
}
/**
* Builder class of DefaultFlowInfo.
*/

View File

@ -15,6 +15,7 @@
*/
package org.onosproject.openstacktelemetry.impl;
import com.google.common.base.Strings;
import org.onosproject.openstacktelemetry.api.InfluxRecord;
import java.util.Objects;
@ -22,14 +23,19 @@ import java.util.Objects;
import static com.google.common.base.MoreObjects.toStringHelper;
import static org.onosproject.openstacktelemetry.api.Constants.DEFAULT_INFLUXDB_MEASUREMENT;
/**
* A default implementation of influx record.
*
* @param <K> key of influx record
* @param <V> value of influx record
*/
public final class DefaultInfluxRecord<K, V> implements InfluxRecord<K, V> {
public static final String MEASUREMENT_NAME = DEFAULT_INFLUXDB_MEASUREMENT;
private final K measurement;
private final V flowInfos;
protected DefaultInfluxRecord(K measurement, V flowInfos) {
if ((measurement == null) || (measurement.equals(""))) {
if (Strings.isNullOrEmpty((String) measurement)) {
this.measurement = (K) MEASUREMENT_NAME;
} else {
this.measurement = measurement;
@ -66,6 +72,7 @@ public final class DefaultInfluxRecord<K, V> implements InfluxRecord<K, V> {
return Objects.hash(measurement, flowInfos);
}
@Override
public String toString() {
return toStringHelper(this)
.add("measurement", measurement)

View File

@ -20,6 +20,8 @@ import org.onlab.packet.IpPrefix;
import org.onlab.packet.TpPort;
import org.onosproject.openstacktelemetry.api.StatsFlowRule;
import java.util.Objects;
import static com.google.common.base.Preconditions.checkArgument;
public final class DefaultStatsFlowRule implements StatsFlowRule {
@ -79,10 +81,43 @@ public final class DefaultStatsFlowRule implements StatsFlowRule {
.toString();
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj instanceof DefaultStatsFlowRule) {
final DefaultStatsFlowRule other = (DefaultStatsFlowRule) obj;
return Objects.equals(this.srcIpPrefix, other.srcIpPrefix) &&
Objects.equals(this.dstIpPrefix, other.dstIpPrefix) &&
Objects.equals(this.srcTpPort, other.srcTpPort) &&
Objects.equals(this.dstTpPort, other.dstTpPort) &&
Objects.equals(this.ipProtocol, other.ipProtocol);
}
return false;
}
@Override
public int hashCode() {
return Objects.hash(srcIpPrefix, dstIpPrefix, srcTpPort, dstTpPort, ipProtocol);
}
/**
* Obtains a default stats flow rule builder object.
*
* @return flow rule builder object
*/
public static Builder builder() {
return new Builder();
}
/**
* Obtains the builder object existing flow rule.
*
* @param flowRule flow rule
* @return builder object
*/
public static Builder from(StatsFlowRule flowRule) {
return new Builder()
.srcIpPrefix(flowRule.srcIpPrefix())

View File

@ -16,6 +16,7 @@
package org.onosproject.openstacktelemetry.impl;
import io.grpc.ManagedChannel;
import io.grpc.ManagedChannelBuilder;
import org.apache.felix.scr.annotations.Activate;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Deactivate;
@ -24,6 +25,7 @@ import org.apache.felix.scr.annotations.ReferenceCardinality;
import org.apache.felix.scr.annotations.Service;
import org.onosproject.openstacktelemetry.api.GrpcTelemetryAdminService;
import org.onosproject.openstacktelemetry.api.OpenstackTelemetryService;
import org.onosproject.openstacktelemetry.api.config.GrpcTelemetryConfig;
import org.onosproject.openstacktelemetry.api.config.TelemetryConfig;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -66,24 +68,22 @@ public class GrpcTelemetryManager implements GrpcTelemetryAdminService {
return;
}
// FIXME do not activate grpc service for now due to deps conflict
// GrpcTelemetryConfig grpcConfig = (GrpcTelemetryConfig) config;
// channel = ManagedChannelBuilder
// .forAddress(grpcConfig.address(), grpcConfig.port())
// .maxInboundMessageSize(grpcConfig.maxInboundMsgSize())
// .usePlaintext(grpcConfig.usePlaintext())
// .build();
GrpcTelemetryConfig grpcConfig = (GrpcTelemetryConfig) config;
channel = ManagedChannelBuilder
.forAddress(grpcConfig.address(), grpcConfig.port())
.maxInboundMessageSize(grpcConfig.maxInboundMsgSize())
.usePlaintext(grpcConfig.usePlaintext())
.build();
log.info("gRPC producer has Started");
}
@Override
public void stop() {
// FIXME do not activate grpc service for now due to deps conflict
// if (channel != null) {
// channel.shutdown();
// channel = null;
// }
if (channel != null) {
channel.shutdown();
channel = null;
}
log.info("gRPC producer has Stopped");
}

View File

@ -15,6 +15,7 @@
*/
package org.onosproject.openstacktelemetry.impl;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Lists;
import org.apache.felix.scr.annotations.Activate;
import org.apache.felix.scr.annotations.Component;
@ -94,6 +95,11 @@ public class OpenstackTelemetryManager implements OpenstackTelemetryService {
});
}
@Override
public Set<TelemetryService> telemetryServices() {
return ImmutableSet.copyOf(telemetryServices);
}
private void invokeGrpcPublisher(GrpcTelemetryService service, Set<FlowInfo> flowInfos) {
// TODO: need provide implementation
}

View File

@ -76,7 +76,9 @@ public class FlowInfoJsonCodecTest {
private static final int INTEGER_VALUE = 1;
private static final short SHORT_VALUE = (short) 1;
/**
* Initial setup for this unit test.
*/
@Before
public void setUp() {
context = new MockCodecContext();

View File

@ -55,6 +55,9 @@ public final class TinaFlowInfoByteBufferCodecTest {
private final TinaFlowInfoByteBufferCodec codec =
new TinaFlowInfoByteBufferCodec();
/**
* Initial setup for this unit test.
*/
@Before
public void setup() {
StatsInfo statsInfo = new DefaultStatsInfo.DefaultBuilder().build();

View File

@ -42,6 +42,9 @@ public class TinaStatsInfoByteBufferCodecTest {
private final TinaStatsInfoByteBufferCodec codec =
new TinaStatsInfoByteBufferCodec();
/**
* Initial setup for this unit test.
*/
@Before
public void setup() {
StatsInfo.Builder builder = new DefaultStatsInfo.DefaultBuilder();
@ -59,6 +62,9 @@ public class TinaStatsInfoByteBufferCodecTest {
.build();
}
/**
* Tests codec encode and decode.
*/
@Test
public void testEncodeDecode() {
ByteBuffer buffer = codec.encode(info);

View File

@ -25,6 +25,7 @@ import java.util.Map;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;
import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutable;
/**
* Unit tests for DefaultGrpcTelemetryConfig class.
@ -52,6 +53,9 @@ public final class DefaultGrpcTelemetryConfigTest {
private GrpcTelemetryConfig sameAsConfig1;
private GrpcTelemetryConfig config2;
/**
* Initial setup for this unit test.
*/
@Before
public void setup() {
@ -87,6 +91,17 @@ public final class DefaultGrpcTelemetryConfigTest {
.build();
}
/**
* Tests class immutability.
*/
@Test
public void testImmutability() {
assertThatClassIsImmutable(DefaultGrpcTelemetryConfig.class);
}
/**
* Tests object equality.
*/
@Test
public void testEquality() {
new EqualsTester()
@ -94,6 +109,9 @@ public final class DefaultGrpcTelemetryConfigTest {
.addEqualityGroup(config2).testEquals();
}
/**
* Tests object construction.
*/
@Test
public void testConstruction() {
GrpcTelemetryConfig config = config1;

View File

@ -25,6 +25,7 @@ import java.util.Map;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;
import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutable;
/**
* Unit tests for DefaultInfluxDbTelemetryConfig class.
@ -61,6 +62,9 @@ public final class DefaultInfluxDbTelemetryConfigTest {
private InfluxDbTelemetryConfig sameAsConfig1;
private InfluxDbTelemetryConfig config2;
/**
* Initial setup for this unit test.
*/
@Before
public void setup() {
@ -105,6 +109,17 @@ public final class DefaultInfluxDbTelemetryConfigTest {
.build();
}
/**
* Tests class immutability.
*/
@Test
public void testImmutability() {
assertThatClassIsImmutable(DefaultInfluxDbTelemetryConfig.class);
}
/**
* Tests object equality.
*/
@Test
public void testEquality() {
new EqualsTester()
@ -112,6 +127,9 @@ public final class DefaultInfluxDbTelemetryConfigTest {
.addEqualityGroup(config2).testEquals();
}
/**
* Tests object construction.
*/
@Test
public void testConstruction() {
InfluxDbTelemetryConfig config = config1;

View File

@ -25,6 +25,7 @@ import java.util.Map;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;
import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutable;
public final class DefaultKafkaTelemetryConfigTest {
@ -63,6 +64,9 @@ public final class DefaultKafkaTelemetryConfigTest {
private KafkaTelemetryConfig sameAsConfig1;
private KafkaTelemetryConfig config2;
/**
* Initial setup for this unit test.
*/
@Before
public void setup() {
@ -113,6 +117,17 @@ public final class DefaultKafkaTelemetryConfigTest {
.build();
}
/**
* Tests class immutability.
*/
@Test
public void testImmutability() {
assertThatClassIsImmutable(DefaultKafkaTelemetryConfig.class);
}
/**
* Tests object equality.
*/
@Test
public void testEquality() {
new EqualsTester()
@ -120,6 +135,9 @@ public final class DefaultKafkaTelemetryConfigTest {
.addEqualityGroup(config2).testEquals();
}
/**
* Tests object construction.
*/
@Test
public void testConstruction() {
KafkaTelemetryConfig config = config1;

View File

@ -25,6 +25,7 @@ import java.util.Map;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;
import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutable;
public final class DefaultRestTelemetryConfigTest {
@ -55,6 +56,9 @@ public final class DefaultRestTelemetryConfigTest {
private RestTelemetryConfig sameAsConfig1;
private RestTelemetryConfig config2;
/**
* Initial setup for this unit test.
*/
@Before
public void setup() {
@ -96,6 +100,17 @@ public final class DefaultRestTelemetryConfigTest {
.build();
}
/**
* Tests class immutability.
*/
@Test
public void testImmutability() {
assertThatClassIsImmutable(DefaultRestTelemetryConfig.class);
}
/**
* Tests object equality.
*/
@Test
public void testEquality() {
new EqualsTester()
@ -103,6 +118,9 @@ public final class DefaultRestTelemetryConfigTest {
.addEqualityGroup(config2).testEquals();
}
/**
* Tests object construction.
*/
@Test
public void testConstruction() {
RestTelemetryConfig config = config1;

View File

@ -29,6 +29,7 @@ import org.onosproject.openstacktelemetry.api.StatsInfo;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;
import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutable;
/**
* Unit tests for DefaultFlowInfo class.
@ -58,8 +59,11 @@ public final class DefaultFlowInfoTest {
private FlowInfo sameAsInfo1;
private FlowInfo info2;
/**
* Initial setup for this unit test.
*/
@Before
public void setup() {
public void setUp() {
FlowInfo.Builder builder1 = new DefaultFlowInfo.DefaultBuilder();
FlowInfo.Builder builder2 = new DefaultFlowInfo.DefaultBuilder();
@ -122,6 +126,17 @@ public final class DefaultFlowInfoTest {
.build();
}
/**
* Tests class immutability.
*/
@Test
public void testImmutability() {
assertThatClassIsImmutable(DefaultFlowInfo.class);
}
/**
* Tests object equality.
*/
@Test
public void testEquality() {
new EqualsTester()
@ -129,6 +144,9 @@ public final class DefaultFlowInfoTest {
.addEqualityGroup(info2).testEquals();
}
/**
* Tests object construction.
*/
@Test
public void testConstruction() {
FlowInfo info = info1;

View File

@ -0,0 +1,153 @@
/*
* Copyright 2018-present Open Networking Foundation
*
* Licensed 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 org.onosproject.openstacktelemetry.impl;
import com.google.common.collect.ImmutableSet;
import com.google.common.testing.EqualsTester;
import org.junit.Before;
import org.junit.Test;
import org.onlab.packet.IpAddress;
import org.onlab.packet.IpPrefix;
import org.onlab.packet.MacAddress;
import org.onlab.packet.TpPort;
import org.onlab.packet.VlanId;
import org.onosproject.net.DeviceId;
import org.onosproject.openstacktelemetry.api.FlowInfo;
import org.onosproject.openstacktelemetry.api.InfluxRecord;
import org.onosproject.openstacktelemetry.api.StatsInfo;
import java.util.Set;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;
import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutable;
/**
* Unit tests for DefaultInfluxRecord class.
*/
public final class DefaultInfluxRecordTest {
private static final String MEASUREMENT_1 = "sonaflow-1";
private static final String MEASUREMENT_2 = "sonaflow-2";
private static final String IP_ADDRESS_1 = "10.10.10.1";
private static final String IP_ADDRESS_2 = "20.20.20.1";
private static final String MAC_ADDRESS_1 = "AA:BB:CC:DD:EE:FF";
private static final String MAC_ADDRESS_2 = "FF:EE:DD:CC:BB:AA";
private static final int IP_PREFIX_LENGTH_1 = 10;
private static final int IP_PREFIX_LENGTH_2 = 20;
private static final int PORT_1 = 1000;
private static final int PORT_2 = 2000;
private static final int STATIC_INTEGER_1 = 1;
private static final int STATIC_INTEGER_2 = 2;
private static final String STATIC_STRING_1 = "1";
private static final String STATIC_STRING_2 = "2";
private InfluxRecord record1;
private InfluxRecord sameAsRecord1;
private InfluxRecord record2;
private Set<FlowInfo> flowInfos1;
private Set<FlowInfo> flowInfos2;
/**
* Initial setup for this unit test.
*/
@Before
public void setUp() {
FlowInfo.Builder builder1 = new DefaultFlowInfo.DefaultBuilder();
FlowInfo.Builder builder2 = new DefaultFlowInfo.DefaultBuilder();
StatsInfo statsInfo = new DefaultStatsInfo.DefaultBuilder().build();
FlowInfo info1 = builder1
.withFlowType((byte) STATIC_INTEGER_1)
.withInputInterfaceId(STATIC_INTEGER_1)
.withOutputInterfaceId(STATIC_INTEGER_1)
.withDeviceId(DeviceId.deviceId(STATIC_STRING_1))
.withSrcIp(IpPrefix.valueOf(
IpAddress.valueOf(IP_ADDRESS_1), IP_PREFIX_LENGTH_1))
.withDstIp(IpPrefix.valueOf(
IpAddress.valueOf(IP_ADDRESS_1), IP_PREFIX_LENGTH_1))
.withSrcPort(TpPort.tpPort(PORT_1))
.withDstPort(TpPort.tpPort(PORT_1))
.withProtocol((byte) STATIC_INTEGER_1)
.withVlanId(VlanId.vlanId(STATIC_STRING_1))
.withSrcMac(MacAddress.valueOf(MAC_ADDRESS_1))
.withDstMac(MacAddress.valueOf(MAC_ADDRESS_1))
.withStatsInfo(statsInfo)
.build();
FlowInfo info2 = builder2
.withFlowType((byte) STATIC_INTEGER_2)
.withInputInterfaceId(STATIC_INTEGER_2)
.withOutputInterfaceId(STATIC_INTEGER_2)
.withDeviceId(DeviceId.deviceId(STATIC_STRING_2))
.withSrcIp(IpPrefix.valueOf(
IpAddress.valueOf(IP_ADDRESS_2), IP_PREFIX_LENGTH_2))
.withDstIp(IpPrefix.valueOf(
IpAddress.valueOf(IP_ADDRESS_2), IP_PREFIX_LENGTH_2))
.withSrcPort(TpPort.tpPort(PORT_2))
.withDstPort(TpPort.tpPort(PORT_2))
.withProtocol((byte) STATIC_INTEGER_2)
.withVlanId(VlanId.vlanId(STATIC_STRING_2))
.withSrcMac(MacAddress.valueOf(MAC_ADDRESS_2))
.withDstMac(MacAddress.valueOf(MAC_ADDRESS_2))
.withStatsInfo(statsInfo)
.build();
flowInfos1 = ImmutableSet.of(info1);
flowInfos2 = ImmutableSet.of(info2);
record1 = new DefaultInfluxRecord(MEASUREMENT_1, flowInfos1);
sameAsRecord1 = new DefaultInfluxRecord(MEASUREMENT_1, flowInfos1);
record2 = new DefaultInfluxRecord(MEASUREMENT_2, flowInfos2);
}
/**
* Tests class immutability.
*/
@Test
public void testImmutability() {
assertThatClassIsImmutable(DefaultInfluxRecord.class);
}
/**
* Tests object equality.
*/
@Test
public void testEquality() {
new EqualsTester()
.addEqualityGroup(record1, sameAsRecord1)
.addEqualityGroup(record2).testEquals();
}
/**
* Tests object construction.
*/
@Test
public void testConstruction() {
InfluxRecord record = record1;
assertThat(record.measurement(), is(MEASUREMENT_1));
assertThat(record.flowInfos(), is(flowInfos1));
}
}

View File

@ -0,0 +1,112 @@
/*
* Copyright 2018-present Open Networking Foundation
*
* Licensed 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 org.onosproject.openstacktelemetry.impl;
import com.google.common.testing.EqualsTester;
import org.junit.Before;
import org.junit.Test;
import org.onlab.packet.IpAddress;
import org.onlab.packet.IpPrefix;
import org.onlab.packet.TpPort;
import org.onosproject.openstacktelemetry.api.StatsFlowRule;
import static org.junit.Assert.assertEquals;
import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutable;
/**
* Unit tests for DefaultStatsFlowRule class.
*/
public final class DefaultStatsFlowRuleTest {
private static final IpAddress IP_ADDRESS_1 = IpAddress.valueOf("10.10.10.1");
private static final IpAddress IP_ADDRESS_2 = IpAddress.valueOf("20.20.20.1");
private static final int IP_PREFIX_LENGTH_1 = 10;
private static final int IP_PREFIX_LENGTH_2 = 20;
private static final int PORT_1 = 1000;
private static final int PORT_2 = 2000;
private static final byte PROTOCOL_1 = 1;
private static final byte PROTOCOL_2 = 2;
private StatsFlowRule rule1;
private StatsFlowRule sameAsRule1;
private StatsFlowRule rule2;
/**
* Initial setup for this unit test.
*/
@Before
public void setUp() {
rule1 = DefaultStatsFlowRule.builder()
.srcIpPrefix(IpPrefix.valueOf(IP_ADDRESS_1, IP_PREFIX_LENGTH_1))
.dstIpPrefix(IpPrefix.valueOf(IP_ADDRESS_2, IP_PREFIX_LENGTH_2))
.srcTpPort(TpPort.tpPort(PORT_1))
.dstTpPort(TpPort.tpPort(PORT_2))
.ipProtocol(PROTOCOL_1)
.build();
sameAsRule1 = DefaultStatsFlowRule.builder()
.srcIpPrefix(IpPrefix.valueOf(IP_ADDRESS_1, IP_PREFIX_LENGTH_1))
.dstIpPrefix(IpPrefix.valueOf(IP_ADDRESS_2, IP_PREFIX_LENGTH_2))
.srcTpPort(TpPort.tpPort(PORT_1))
.dstTpPort(TpPort.tpPort(PORT_2))
.ipProtocol(PROTOCOL_1)
.build();
rule2 = DefaultStatsFlowRule.builder()
.srcIpPrefix(IpPrefix.valueOf(IP_ADDRESS_2, IP_PREFIX_LENGTH_2))
.dstIpPrefix(IpPrefix.valueOf(IP_ADDRESS_1, IP_PREFIX_LENGTH_1))
.srcTpPort(TpPort.tpPort(PORT_2))
.dstTpPort(TpPort.tpPort(PORT_1))
.ipProtocol(PROTOCOL_2)
.build();
}
/**
* Tests class immutability.
*/
@Test
public void testImmutability() {
assertThatClassIsImmutable(DefaultStatsFlowRule.class);
}
/**
* Tests object equality.
*/
@Test
public void testEquality() {
new EqualsTester()
.addEqualityGroup(rule1, sameAsRule1)
.addEqualityGroup(rule2).testEquals();
}
/**
* Tests object construction.
*/
@Test
public void testConstruction() {
StatsFlowRule rule = rule1;
assertEquals(IpPrefix.valueOf(IP_ADDRESS_1, IP_PREFIX_LENGTH_1), rule.srcIpPrefix());
assertEquals(IpPrefix.valueOf(IP_ADDRESS_2, IP_PREFIX_LENGTH_2), rule.dstIpPrefix());
assertEquals(TpPort.tpPort(PORT_1), rule.srcTpPort());
assertEquals(TpPort.tpPort(PORT_2), rule.dstTpPort());
assertEquals(PROTOCOL_1, rule.ipProtocol());
}
}

View File

@ -22,6 +22,7 @@ import org.onosproject.openstacktelemetry.api.StatsInfo;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;
import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutable;
/**
* Unit tests for DefaultStatsInfo class.
@ -35,6 +36,9 @@ public final class DefaultStatsInfoTest {
private StatsInfo sameAsInfo1;
private StatsInfo info2;
/**
* Initial setup for this unit test.
*/
@Before
public void setup() {
StatsInfo.Builder builder1 = new DefaultStatsInfo.DefaultBuilder();
@ -78,6 +82,17 @@ public final class DefaultStatsInfoTest {
.build();
}
/**
* Tests class immutability.
*/
@Test
public void testImmutability() {
assertThatClassIsImmutable(DefaultStatsInfo.class);
}
/**
* Tests object equality.
*/
@Test
public void testEquality() {
new EqualsTester()
@ -85,6 +100,9 @@ public final class DefaultStatsInfoTest {
.addEqualityGroup(info2).testEquals();
}
/**
* Tests object construction.
*/
@Test
public void testConstruction() {
StatsInfo info = info1;

View File

@ -0,0 +1,50 @@
/*
* Copyright 2018-present Open Networking Foundation
*
* Licensed 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 org.onosproject.openstacktelemetry.impl;
import org.junit.Test;
import org.onlab.junit.TestUtils;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
/**
* Unit tests for gRPC telemetry manager.
*/
public final class GrpcTelemetryManagerTest {
private GrpcTelemetryManager manager;
private OpenstackTelemetryServiceAdapter telemetryService =
new OpenstackTelemetryServiceAdapter();
/**
* Tests codec register activation and deactivation.
*/
@Test
public void testActivateDeactivate() {
manager = new GrpcTelemetryManager();
TestUtils.setField(manager, "openstackTelemetryService", telemetryService);
manager.activate();
assertTrue(telemetryService.services.contains(manager));
manager.deactivate();
assertFalse(telemetryService.services.contains(manager));
}
}

View File

@ -0,0 +1,50 @@
/*
* Copyright 2018-present Open Networking Foundation
*
* Licensed 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 org.onosproject.openstacktelemetry.impl;
import org.junit.Test;
import org.onlab.junit.TestUtils;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
/**
* Unit tests for influxDB telemetry manager.
*/
public final class InfluxDbTelemetryManagerTest {
private InfluxDbTelemetryManager manager;
private OpenstackTelemetryServiceAdapter telemetryService =
new OpenstackTelemetryServiceAdapter();
/**
* Tests codec register activation and deactivation.
*/
@Test
public void testActivateDeactivate() {
manager = new InfluxDbTelemetryManager();
TestUtils.setField(manager, "openstackTelemetryService", telemetryService);
manager.activate();
assertTrue(telemetryService.services.contains(manager));
manager.deactivate();
assertFalse(telemetryService.services.contains(manager));
}
}

View File

@ -0,0 +1,50 @@
/*
* Copyright 2018-present Open Networking Foundation
*
* Licensed 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 org.onosproject.openstacktelemetry.impl;
import org.junit.Test;
import org.onlab.junit.TestUtils;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
/**
* Unit tests for kafka telemetry manager.
*/
public final class KafkaTelemetryManagerTest {
private KafkaTelemetryManager manager;
private OpenstackTelemetryServiceAdapter telemetryService =
new OpenstackTelemetryServiceAdapter();
/**
* Tests codec register activation and deactivation.
*/
@Test
public void testActivateDeactivate() {
manager = new KafkaTelemetryManager();
TestUtils.setField(manager, "openstackTelemetryService", telemetryService);
manager.activate();
assertTrue(telemetryService.services.contains(manager));
manager.deactivate();
assertFalse(telemetryService.services.contains(manager));
}
}

View File

@ -0,0 +1,87 @@
/*
* Copyright 2018-present Open Networking Foundation
*
* Licensed 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 org.onosproject.openstacktelemetry.impl;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.onosproject.openstacktelemetry.api.TelemetryService;
import static org.junit.Assert.assertEquals;
/**
* Unit tests for OpenstackTelemetryService class.
*/
public final class OpenstackTelemetryManagerTest {
private static final TelemetryService GRPC_SERVICE = new GrpcTelemetryManager();
private static final TelemetryService INFLUXDB_SERVICE = new InfluxDbTelemetryManager();
private OpenstackTelemetryManager manager;
/**
* Initializes the unit test.
*/
@Before
public void setUp() {
manager = new OpenstackTelemetryManager();
manager.activate();
}
/**
* Tests addTelemetryService method.
*/
@Test
public void testAddTelemetryService() {
addDefaultServices();
TelemetryService kafkaService = new KafkaTelemetryManager();
assertEquals(2, manager.telemetryServices().size());
manager.addTelemetryService(kafkaService);
assertEquals(3, manager.telemetryServices().size());
}
/**
* Tests removeTelemetryService method.
*/
@Test
public void testRemoveTelemetryService() {
addDefaultServices();
assertEquals(2, manager.telemetryServices().size());
manager.removeTelemetryService(GRPC_SERVICE);
assertEquals(1, manager.telemetryServices().size());
}
/**
* Tears down the unit test.
*/
@After
public void tearDown() {
manager.deactivate();
}
private void addDefaultServices() {
manager.addTelemetryService(GRPC_SERVICE);
manager.addTelemetryService(INFLUXDB_SERVICE);
}
}

View File

@ -0,0 +1,52 @@
/*
* Copyright 2018-present Open Networking Foundation
*
* Licensed 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 org.onosproject.openstacktelemetry.impl;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Sets;
import org.onosproject.openstacktelemetry.api.FlowInfo;
import org.onosproject.openstacktelemetry.api.OpenstackTelemetryService;
import org.onosproject.openstacktelemetry.api.TelemetryService;
import java.util.Set;
/**
* A mock up test class of openstack telemetry service.
*/
public class OpenstackTelemetryServiceAdapter implements OpenstackTelemetryService {
Set<TelemetryService> services = Sets.newConcurrentHashSet();
@Override
public void addTelemetryService(TelemetryService telemetryService) {
services.add(telemetryService);
}
@Override
public void removeTelemetryService(TelemetryService telemetryService) {
services.remove(telemetryService);
}
@Override
public void publish(Set<FlowInfo> flowInfos) {
}
@Override
public Set<TelemetryService> telemetryServices() {
return ImmutableSet.copyOf(services);
}
}

View File

@ -0,0 +1,51 @@
/*
* Copyright 2018-present Open Networking Foundation
*
* Licensed 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 org.onosproject.openstacktelemetry.impl;
import org.junit.Test;
import org.onlab.junit.TestUtils;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
/**
* Unit tests for REST telemetry manager.
*/
public final class RestTelemetryManagerTest {
private RestTelemetryManager manager;
private OpenstackTelemetryServiceAdapter telemetryService =
new OpenstackTelemetryServiceAdapter();
/**
* Tests codec register activation and deactivation.
*/
@Test
public void testActivateDeactivate() {
manager = new RestTelemetryManager();
TestUtils.setField(manager, "openstackTelemetryService", telemetryService);
manager.activate();
assertTrue(telemetryService.services.contains(manager));
manager.deactivate();
assertFalse(telemetryService.services.contains(manager));
}
}