Replaced policy-utils/Triple with apache Triple.
Issue-ID: POLICY-2694
Change-Id: I160f90c03f18b7da8dec5d0a00f809bcfb29680b
Signed-off-by: Jim Hahn <jrh3@att.com>
* ============LICENSE_START=======================================================
* ONAP
* ================================================================================
- * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2018, 2020 AT&T Intellectual Property. All rights reserved.
* Modifications Copyright (C) 2020 Nordix Foundation
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
import java.util.Arrays;
import java.util.Map;
import org.apache.commons.lang3.tuple.Pair;
+import org.apache.commons.lang3.tuple.Triple;
import org.junit.Before;
import org.junit.Test;
import org.onap.policy.drools.pooling.message.BucketAssignments;
import org.onap.policy.drools.pooling.message.Message;
import org.onap.policy.drools.pooling.message.Offline;
import org.onap.policy.drools.pooling.message.Query;
-import org.onap.policy.drools.utils.Triple;
public class ActiveStateTest extends SupportBasicStateTester {
// heart beat generator
timer = repeatedTasks.remove();
- assertEquals(STD_INTER_HEARTBEAT_MS, timer.first().longValue());
- assertEquals(STD_INTER_HEARTBEAT_MS, timer.second().longValue());
+ assertEquals(STD_INTER_HEARTBEAT_MS, timer.getLeft().longValue());
+ assertEquals(STD_INTER_HEARTBEAT_MS, timer.getMiddle().longValue());
// my heart beat checker
timer = repeatedTasks.remove();
- assertEquals(STD_ACTIVE_HEARTBEAT_MS, timer.first().longValue());
- assertEquals(STD_ACTIVE_HEARTBEAT_MS, timer.second().longValue());
+ assertEquals(STD_ACTIVE_HEARTBEAT_MS, timer.getLeft().longValue());
+ assertEquals(STD_ACTIVE_HEARTBEAT_MS, timer.getMiddle().longValue());
// predecessor's heart beat checker
timer = repeatedTasks.remove();
- assertEquals(STD_ACTIVE_HEARTBEAT_MS, timer.first().longValue());
- assertEquals(STD_ACTIVE_HEARTBEAT_MS, timer.second().longValue());
+ assertEquals(STD_ACTIVE_HEARTBEAT_MS, timer.getLeft().longValue());
+ assertEquals(STD_ACTIVE_HEARTBEAT_MS, timer.getMiddle().longValue());
}
@Test
// heart beat generator
timer = repeatedTasks.remove();
- assertEquals(STD_INTER_HEARTBEAT_MS, timer.first().longValue());
- assertEquals(STD_INTER_HEARTBEAT_MS, timer.second().longValue());
+ assertEquals(STD_INTER_HEARTBEAT_MS, timer.getLeft().longValue());
+ assertEquals(STD_INTER_HEARTBEAT_MS, timer.getMiddle().longValue());
// my heart beat checker
timer = repeatedTasks.remove();
- assertEquals(STD_ACTIVE_HEARTBEAT_MS, timer.first().longValue());
- assertEquals(STD_ACTIVE_HEARTBEAT_MS, timer.second().longValue());
+ assertEquals(STD_ACTIVE_HEARTBEAT_MS, timer.getLeft().longValue());
+ assertEquals(STD_ACTIVE_HEARTBEAT_MS, timer.getMiddle().longValue());
}
@Test
verify(mgr).publish(anyString(), any(Heartbeat.class));
// fire the task
- assertNull(task.third().fire());
+ assertNull(task.getRight().fire());
// should have generated a second pair of heart beats
verify(mgr, times(2)).publish(anyString(), any(Heartbeat.class));
when(mgr.goInactive()).thenReturn(next);
// fire the task - should not transition
- assertNull(task.third().fire());
+ assertNull(task.getRight().fire());
verify(mgr, never()).publishAdmin(any(Query.class));
}
when(mgr.goStart()).thenReturn(next);
// fire the task - should transition
- assertEquals(next, task.third().fire());
+ assertEquals(next, task.getRight().fire());
// should continue to distribute
verify(mgr, never()).startDistributing(null);
when(mgr.goQuery()).thenReturn(next);
// fire the task - should NOT transition
- assertNull(task.third().fire());
+ assertNull(task.getRight().fire());
verify(mgr, never()).publishAdmin(any(Query.class));
}
when(mgr.goQuery()).thenReturn(next);
// fire the task - should transition
- assertEquals(next, task.third().fire());
+ assertEquals(next, task.getRight().fire());
verify(mgr).publishAdmin(any(Query.class));
}
* ============LICENSE_START=======================================================
* ONAP
* ================================================================================
- * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2018, 2020 AT&T Intellectual Property. All rights reserved.
* Modifications Copyright (C) 2020 Nordix Foundation
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
import java.util.Map;
import org.apache.commons.lang3.tuple.Pair;
+import org.apache.commons.lang3.tuple.Triple;
import org.junit.Before;
import org.junit.Test;
import org.onap.policy.drools.pooling.message.Forward;
import org.onap.policy.drools.pooling.message.Message;
import org.onap.policy.drools.pooling.message.Offline;
import org.onap.policy.drools.pooling.message.Query;
-import org.onap.policy.drools.utils.Triple;
public class StartStateTest extends SupportBasicStateTester {
*/
Triple<Long, Long, StateTimerTask> generator = repeatedTasks.removeFirst();
- assertEquals(STD_INTER_HEARTBEAT_MS, generator.first().longValue());
- assertEquals(STD_INTER_HEARTBEAT_MS, generator.second().longValue());
+ assertEquals(STD_INTER_HEARTBEAT_MS, generator.getLeft().longValue());
+ assertEquals(STD_INTER_HEARTBEAT_MS, generator.getMiddle().longValue());
// invoke the task - it should generate another heartbeat
- assertEquals(null, generator.third().fire());
+ assertEquals(null, generator.getRight().fire());
verify(mgr, times(2)).publish(MY_HOST, msg.getRight());
// and again
- assertEquals(null, generator.third().fire());
+ assertEquals(null, generator.getRight().fire());
verify(mgr, times(3)).publish(MY_HOST, msg.getRight());
* ============LICENSE_START=======================================================
* ONAP
* ================================================================================
- * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2018, 2020 AT&T Intellectual Property. All rights reserved.
* Modifications Copyright (C) 2020 Nordix Foundation
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
import java.util.TreeSet;
import java.util.concurrent.atomic.AtomicReference;
import org.apache.commons.lang3.tuple.Pair;
+import org.apache.commons.lang3.tuple.Triple;
import org.onap.policy.drools.pooling.CancellableScheduledTask;
import org.onap.policy.drools.pooling.PoolingManager;
import org.onap.policy.drools.pooling.PoolingProperties;
import org.onap.policy.drools.pooling.message.BucketAssignments;
import org.onap.policy.drools.pooling.message.Leader;
import org.onap.policy.drools.pooling.message.Message;
-import org.onap.policy.drools.utils.Triple;
/**
* Superclass used to test subclasses of {@link State}.
// capture scheduleWithFixedDelay() arguments, and return a new future
when(mgr.scheduleWithFixedDelay(anyLong(), anyLong(), any(StateTimerTask.class))).thenAnswer(invocation -> {
Object[] args = invocation.getArguments();
- repeatedTasks.add(new Triple<>((Long) args[0], (Long) args[1], (StateTimerTask) args[2]));
+ repeatedTasks.add(Triple.of((Long) args[0], (Long) args[1], (StateTimerTask) args[2]));
CancellableScheduledTask sched = mock(CancellableScheduledTask.class);
repeatedSchedules.add(sched);
import java.nio.file.Paths;
import java.util.List;
import java.util.Properties;
+import lombok.AllArgsConstructor;
+import lombok.Getter;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.onap.policy.drools.protocol.coders.EventProtocolCoder.CoderFilters;
import org.onap.policy.drools.protocol.coders.TopicCoderFilterConfiguration.CustomGsonCoder;
import org.onap.policy.drools.util.KieUtils;
-import org.onap.policy.drools.utils.Triple;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
*/
@BeforeClass
public static void setUpClass() throws IOException {
- releaseId = KieUtils.installArtifact(
- Paths.get(MavenDroolsControllerTest.JUNIT_ECHO_KMODULE_PATH).toFile(),
- Paths.get(MavenDroolsControllerTest.JUNIT_ECHO_KMODULE_POM_PATH).toFile(),
- MavenDroolsControllerTest.JUNIT_ECHO_KJAR_DRL_PATH,
- Paths.get(MavenDroolsControllerTest.JUNIT_ECHO_KMODULE_DRL_PATH).toFile());
+ releaseId = KieUtils.installArtifact(Paths.get(MavenDroolsControllerTest.JUNIT_ECHO_KMODULE_PATH).toFile(),
+ Paths.get(MavenDroolsControllerTest.JUNIT_ECHO_KMODULE_POM_PATH).toFile(),
+ MavenDroolsControllerTest.JUNIT_ECHO_KJAR_DRL_PATH,
+ Paths.get(MavenDroolsControllerTest.JUNIT_ECHO_KMODULE_DRL_PATH).toFile());
}
/**
* @param protocolFilter protocol filter
*/
private void testGsonToolset(JsonProtocolFilter protocolFilter) {
- GsonProtocolCoderToolset gsonToolset = new GsonProtocolCoderToolset(
- EventProtocolParams.builder().topic(JUNIT_PROTOCOL_CODER_TOPIC)
- .groupId(releaseId.getGroupId())
- .artifactId(releaseId.getArtifactId())
- .eventClass(Triple.class.getName())
- .protocolFilter(protocolFilter)
- .customGsonCoder(null)
- .modelClassLoaderHash(12345678), CONTROLLER_ID);
+ GsonProtocolCoderToolset gsonToolset =
+ new GsonProtocolCoderToolset(EventProtocolParams.builder().topic(JUNIT_PROTOCOL_CODER_TOPIC)
+ .groupId(releaseId.getGroupId()).artifactId(releaseId.getArtifactId())
+ .eventClass(ThreeStrings.class.getName()).protocolFilter(protocolFilter)
+ .customGsonCoder(null).modelClassLoaderHash(12345678), CONTROLLER_ID);
Assert.assertNotNull(gsonToolset.getEncoder());
Assert.assertNotNull(gsonToolset.getDecoder());
testToolset(protocolFilter, gsonToolset);
- Triple<String, String, String> triple = createTriple();
+ ThreeStrings triple = createTriple();
gsonToolset.setCustomCoder(new CustomGsonCoder(this.getClass().getName(), "customCoder"));
String tripleEncoded = encode(gsonToolset, triple);
decode(protocolFilter, gsonToolset, triple, tripleEncoded);
}
- private Triple<String, String, String> createTriple() {
- return new Triple<>("v1", "v2", "v3");
+ private ThreeStrings createTriple() {
+ return new ThreeStrings("v1", "v2", "v3");
}
private void testToolset(JsonProtocolFilter protocolFilter, ProtocolCoderToolset coderToolset) {
addRemoveCoder(coderToolset);
/* restore original filters */
- coderToolset.addCoder(Triple.class.getName(), protocolFilter, 654321);
+ coderToolset.addCoder(ThreeStrings.class.getName(), protocolFilter, 654321);
- Triple<String, String, String> triple = createTriple();
+ ThreeStrings triple = createTriple();
String tripleEncoded = encode(coderToolset, triple);
decode(protocolFilter, coderToolset, triple, tripleEncoded);
}
- @SuppressWarnings("unchecked")
private void decode(JsonProtocolFilter protocolFilter, ProtocolCoderToolset coderToolset,
- Triple<String, String, String> triple, String tripleEncoded) {
+ ThreeStrings triple, String tripleEncoded) {
- Triple<String, String, String> tripleDecoded = null;
+ ThreeStrings tripleDecoded = null;
try {
- tripleDecoded = (Triple<String, String, String>) coderToolset.decode(tripleEncoded);
+ tripleDecoded = (ThreeStrings) coderToolset.decode(tripleEncoded);
} catch (UnsupportedOperationException e) {
/* OK */
logger.trace("Junit expected exception - decode does not pass filtering", e);
}
- CoderFilters coderFilters = coderToolset.getCoder(Triple.class.getName());
- Assert.assertSame(coderFilters.getCodedClass(), Triple.class.getName());
+ CoderFilters coderFilters = coderToolset.getCoder(ThreeStrings.class.getName());
+ Assert.assertSame(coderFilters.getCodedClass(), ThreeStrings.class.getName());
Assert.assertSame(coderFilters.getFilter(), protocolFilter);
Assert.assertNotNull(coderFilters.getFilter().getRule());
coderFilters.getFilter().setRule("[?($.second =~ /^v2$/ && $.third =~ /.*v3.*/)]");
- tripleDecoded = (Triple<String, String, String>) coderToolset.decode(tripleEncoded);
+ tripleDecoded = (ThreeStrings) coderToolset.decode(tripleEncoded);
- Assert.assertEquals(triple.first(), tripleDecoded.first());
- Assert.assertEquals(triple.second(), tripleDecoded.second());
- Assert.assertEquals(triple.third(), tripleDecoded.third());
+ Assert.assertEquals(triple.getFirst(), tripleDecoded.getFirst());
+ Assert.assertEquals(triple.getSecond(), tripleDecoded.getSecond());
+ Assert.assertEquals(triple.getThird(), tripleDecoded.getThird());
coderFilters.getFilter().setRule(null);
Assert.assertEquals("[?($ =~ /.*/)]", coderFilters.getFilter().getRule());
- tripleDecoded = (Triple<String, String, String>) coderToolset.decode(tripleEncoded);
+ tripleDecoded = (ThreeStrings) coderToolset.decode(tripleEncoded);
- Assert.assertEquals(tripleDecoded.first(), triple.first());
- Assert.assertEquals(tripleDecoded.second(), triple.second());
- Assert.assertEquals(tripleDecoded.third(), triple.third());
+ Assert.assertEquals(tripleDecoded.getFirst(), triple.getFirst());
+ Assert.assertEquals(tripleDecoded.getSecond(), triple.getSecond());
+ Assert.assertEquals(tripleDecoded.getThird(), triple.getThird());
coderFilters.getFilter().setRule("[?($.third =~ /.*v3.*/)]");
}
- private String encode(ProtocolCoderToolset coderToolset, Triple<String, String, String> triple) {
+ private String encode(ProtocolCoderToolset coderToolset, ThreeStrings triple) {
String tripleEncoded = coderToolset.encode(triple);
Assert.assertTrue(!tripleEncoded.isEmpty());
return tripleEncoded;
}
private void addRemoveCoder(ProtocolCoderToolset coderToolset) {
- coderToolset.addCoder(this.getClass().getName(),
- new JsonProtocolFilter("[?($.second =~ /.*/)]"), 654321);
+ coderToolset.addCoder(this.getClass().getName(), new JsonProtocolFilter("[?($.second =~ /.*/)]"), 654321);
Assert.assertEquals(2, coderToolset.getCoders().size());
coderToolset.removeCoders(this.getClass().getName());
}
private void updateCoderFilterRule(ProtocolCoderToolset coderToolset) {
- coderToolset.addCoder(Triple.class.getName(), new JsonProtocolFilter("[?($.third =~ /.*/)]"), 654321);
+ coderToolset.addCoder(ThreeStrings.class.getName(), new JsonProtocolFilter("[?($.third =~ /.*/)]"), 654321);
Assert.assertEquals(1, coderToolset.getCoders().size());
- Assert.assertEquals(654321, coderToolset.getCoder(Triple.class.getName()).getModelClassLoaderHash());
+ Assert.assertEquals(654321, coderToolset.getCoder(ThreeStrings.class.getName()).getModelClassLoaderHash());
- Assert.assertNotNull(
- coderToolset.getCoder(
- Triple.class.getName()).getFilter().getRule());
+ Assert.assertNotNull(coderToolset.getCoder(ThreeStrings.class.getName()).getFilter().getRule());
- Assert.assertEquals("[?($.third =~ /.*/)]", coderToolset.getCoder(Triple.class.getName())
- .getFilter().getRule());
+ Assert.assertEquals("[?($.third =~ /.*/)]",
+ coderToolset.getCoder(ThreeStrings.class.getName()).getFilter().getRule());
}
private void validateInitialization(JsonProtocolFilter protocolFilter, ProtocolCoderToolset coderToolset) {
CoderFilters coderFilters = coderToolset.getCoder(CONTROLLER_ID);
Assert.assertNull(coderFilters);
- coderFilters = coderToolset.getCoder(Triple.class.getName());
+ coderFilters = coderToolset.getCoder(ThreeStrings.class.getName());
Assert.assertNotNull(coderFilters);
Assert.assertEquals(coderFilters.getFilter(), protocolFilter);
droolsControllerConfig.put(DroolsPropertyConstants.RULES_GROUPID, releaseId.getGroupId());
droolsControllerConfig.put(DroolsPropertyConstants.RULES_ARTIFACTID, releaseId.getArtifactId());
droolsControllerConfig.put(DroolsPropertyConstants.RULES_VERSION, releaseId.getVersion());
- droolsControllerConfig.put(PolicyEndPointProperties.PROPERTY_NOOP_SINK_TOPICS + "." + JUNIT_PROTOCOL_CODER_TOPIC
- + PolicyEndPointProperties.PROPERTY_TOPIC_EVENTS_SUFFIX, Triple.class.getName());
+ droolsControllerConfig.put(
+ PolicyEndPointProperties.PROPERTY_NOOP_SINK_TOPICS + "." + JUNIT_PROTOCOL_CODER_TOPIC
+ + PolicyEndPointProperties.PROPERTY_TOPIC_EVENTS_SUFFIX,
+ ThreeStrings.class.getName());
return DroolsControllerConstants.getFactory().build(droolsControllerConfig, null, noopTopics);
}
private JsonProtocolFilter createFilterSet() {
return new JsonProtocolFilter("[?($.first =~ /.*/ && $.second =~ /^blah.*/ && $.third =~ /^hello$/)]");
}
+
+ /**
+ * Note: We need an object that can be constructed, but the apache Triple cannot, thus
+ * we create our own class just for these tests.
+ */
+ @Getter
+ @AllArgsConstructor
+ public static class ThreeStrings {
+ private String first;
+ private String second;
+ private String third;
+ }
}
+++ /dev/null
-/*-
- * ============LICENSE_START=======================================================
- * ONAP
- * ================================================================================
- * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
- * ================================================================================
- * 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.
- * ============LICENSE_END=========================================================
- */
-
-package org.onap.policy.drools.utils;
-
-public class Triple<F, S, T> {
-
- private F first;
- private S second;
- private T third;
-
- public Triple() {
- // empty constructor
- }
-
- /**
- * Constructor.
- *
- * @param first first
- * @param second second
- * @param third third
- */
- public Triple(F first, S second, T third) {
- this.first = first;
- this.second = second;
- this.third = third;
- }
-
- public F first() {
- return this.getFirst();
- }
-
- public void first(F first) {
- this.setFirst(first);
- }
-
- public F getFirst() {
- return first;
- }
-
- public void setFirst(F first) {
- this.first = first;
- }
-
- public S second() {
- return this.getSecond();
- }
-
- public void second(S second) {
- this.setSecond(second);
- }
-
- public S getSecond() {
- return second;
- }
-
- public void setSecond(S second) {
- this.second = second;
- }
-
- public T third() {
- return this.getThird();
- }
-
- public void third(T third) {
- this.setThird(third);
- }
-
- public T getThird() {
- return this.third;
- }
-
- public void setThird(T third) {
- this.third = third;
- }
-}
+++ /dev/null
-/*
- * ============LICENSE_START=======================================================
- * ONAP
- * ================================================================================
- * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved.
- * Modifications Copyright (C) 2020 Nordix 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.
- * ============LICENSE_END=========================================================
- */
-
-package org.onap.policy.drools.utils;
-
-import org.junit.Assert;
-import org.junit.Test;
-
-public class TripleTest {
-
- @Test
- public void test() {
- Triple<String, String, String> triple =
- new Triple<>("one", "two", "three");
-
- Assert.assertEquals("one", triple.first());
- Assert.assertEquals("one", triple.getFirst());
-
- Assert.assertEquals("two", triple.second());
- Assert.assertEquals("two", triple.getSecond());
-
- Assert.assertEquals("three", triple.third());
- Assert.assertEquals("three", triple.getThird());
-
- triple.first("I");
- Assert.assertEquals("I", triple.first());
-
- triple.setFirst("1");
- Assert.assertEquals("1", triple.first());
-
- triple.second("2");
- Assert.assertEquals("2", triple.second());
-
- triple.setSecond("II");
- Assert.assertEquals("II", triple.second());
-
- triple.third("3");
- Assert.assertEquals("3", triple.third());
-
- triple.setThird("III");
- Assert.assertEquals("III", triple.third());
-
- }
-}
\ No newline at end of file