* ============LICENSE_START=======================================================
* Common Utils-Test
* ================================================================================
- * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2018-2019 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.
/**
* Constructor.
- *
+ *
* @param nthreads number of threads that will be sleeping simultaneously
*/
public TestTimeMulti(int nthreads) {
* Indicates that a thread has terminated or that it will no longer be invoking
* {@link #sleep(long)}. Awakens the next sleeping thread, if the queue is full after
* removing the terminated thread.
- *
+ *
* @throws IllegalStateException if the queue is already full
*/
public void threadCompleted() {
/**
* Constructor.
- *
+ *
* @param awakenAtMs time, in milliseconds, at which the associated thread should
* awaken
*/
/**
* Blocks the current thread until awakened (i.e., until its latch is
* decremented).
- *
+ *
* @throws InterruptedException can be interrupted
*/
public void await() throws InterruptedException {
* ============LICENSE_START=======================================================
* Common Utils-Test
* ================================================================================
- * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2018-2019 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.
package org.onap.policy.common.utils.time;
+import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
}
assertTrue(ttm.getMillis() >= tbeg + NTIMES * MIN_SLEEP_MS);
+
+ // something in the queue, but no threads remain -> exception
+ assertThatIllegalStateException().isThrownBy(() -> ttm.threadCompleted());
}
private class MyThread extends Thread {
public void run() {
try {
for (int x = 0; x < NTIMES; ++x) {
+ // negative sleep should have no effect
+ texpected = ttm.getMillis();
+ ttm.sleep(-1);
+ if ((tactual = ttm.getMillis()) != texpected) {
+ break;
+ }
+
texpected = ttm.getMillis() + sleepMs;
ttm.sleep(sleepMs);
* ============LICENSE_START=======================================================
* ONAP Policy Engine - Common Modules
* ================================================================================
- * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2018-2019 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.
* subclass. The values of the fields are set via <i>setXxx()</i> methods. As a result, if
* a field is annotated and there is no corresponding <i>setXxx()</i> method, then an
* exception will be thrown.
- *
+ *
* <p>It is possible that an invalid <i>defaultValue</i> is specified via the
* {@link Property} annotation. This could remain undetected until an optional property is
* left out of the {@link Properties}. Consequently, this class will always validate a
/**
* Initializes each "@Property" field with its value, as found in the properties.
- *
+ *
* @param props properties from which to extract the values
* @throws PropertyException if an error occurs
*/
/**
* Walks the class hierarchy of "this" object, populating fields defined in each
* class, using values extracted from the given property set.
- *
+ *
* @param props properties from which to extract the values
* @throws PropertyException if an error occurs
*/
/**
* Sets a field's value, within an object, based on what's in the properties.
- *
+ *
* @param field field whose value is to be set
* @param props properties from which to get the value
* @return {@code true} if the property's value was set, {@code false} otherwise
/**
* Sets a field's value from a particular property.
- *
+ *
* @param setter method to be used to set the field's value
* @param field field whose value is to be set
* @param props properties from which to get the value
/**
* Get the setter.
- *
+ *
* @param field field whose value is to be set
* @param prop property of interest
* @return the method to be used to set the field's value
/**
* Gets a property value, coercing it to the field's type.
- *
+ *
* @param field field whose value is to be set
* @param props properties from which to get the value
* @param prop property of interest
/**
* Verifies that the field can be modified, i.e., it's neither <i>static</i>, nor
* <i>final</i>.
- *
+ *
* @param field field whose value is to be set
* @param prop property of interest
* @throws PropertyAccessException if the field is not modifiable
/**
* Verifies that the setter method is not <i>static</i>.
- *
+ *
* @param setter method to be checked
* @param prop property of interest
* @throws PropertyAccessException if the method is static
/**
* Gets a property value, coercing it to a String.
- *
+ *
* @param fieldName field whose value is to be set
* @param props properties from which to get the value
* @param prop property of interest
/**
* Gets a property value, coercing it to a Boolean.
- *
+ *
* @param fieldName field whose value is to be set
* @param props properties from which to get the value
* @param prop property of interest
/**
* Gets a property value, coercing it to an Integer.
- *
+ *
* @param fieldName field whose value is to be set
* @param props properties from which to get the value
* @param prop property of interest
/**
* Gets a property value, coercing it to a Long.
- *
+ *
* @param fieldName field whose value is to be set
* @param props properties from which to get the value
* @param prop property of interest
/**
* Gets a value from the property set.
- *
+ *
* @param fieldName field whose value is to be set
* @param props properties from which to get the value
* @param prop property of interest
/**
* Gets the property value, straight from the property set.
- *
+ *
* @param props properties from which to get the value
* @param propnm name of the property of interest
* @return the raw property value
/**
* Coerces a String value into a Boolean.
- *
+ *
* @param fieldName field whose value is to be set
* @param prop property of interest
* @param value value to be coerced
* @throws PropertyInvalidException if the value does not represent a valid Boolean
*/
private Boolean makeBoolean(String fieldName, Property prop, String value) throws PropertyInvalidException {
- if ("true".equals(value.toLowerCase())) {
+ if ("true".equalsIgnoreCase(value)) {
return Boolean.TRUE;
- } else if ("false".equals(value.toLowerCase())) {
+ } else if ("false".equalsIgnoreCase(value)) {
return Boolean.FALSE;
} else {
/**
* Coerces a String value into an Integer.
- *
+ *
* @param fieldName field whose value is to be set
* @param prop property of interest
* @param value value to be coerced
/**
* Coerces a String value into a Long.
- *
+ *
* @param fieldName field whose value is to be set
* @param prop property of interest
* @param value value to be coerced
* Applies a function to check a property's default value. If the function throws an
* exception about an invalid property, then it's re-thrown as an exception about an
* invalid <i>defaultValue</i>.
- *
+ *
* @param fieldName name of the field being checked
* @param prop property of interest
* @param func function to invoke to check the default value
func.apply(null);
} catch (PropertyInvalidException ex) {
- throw new PropertyInvalidException(ex.getPropertyName(), fieldName, "defaultValue is invalid",
- ex.getCause());
+ throw new PropertyInvalidException(ex.getPropertyName(), fieldName, "defaultValue is invalid", ex);
}
}
}
/**
* Determines if a value is OK, even if it's empty.
- *
+ *
* @param prop property specifying what's acceptable
* @param value value to be checked
* @return {@code true} if the value is not empty or empty is allowed, {@code false}
/**
* Determines if a {@link Property}'s <i>accept</i> attribute includes the "empty"
* option.
- *
+ *
* @param prop property whose <i>accept</i> attribute is to be examined
* @return {@code true} if the <i>accept</i> attribute includes "empty"
*/
/**
* Checks the default value.
- *
+ *
* @param arg always {@code null}
* @throws PropertyInvalidException if an error occurs
*/
/**
* Name of the property.
- *
+ *
* @return the property name
*/
public String name();
/**
* Default value, used when the property does not exist.
- *
+ *
* @return the default value
*/
public String defaultValue() default "";
/**
* Comma-separated options identifying what's acceptable. The word, "empty",
* indicates that an empty string, "", is an acceptable value.
- *
+ *
* @return options identifying what's acceptable
*/
public String accept() default "";
-
}
}