use of org.apache.ignite.SystemProperty in project ignite by apache.
the class CommandLineStartup method printSystemPropertiesInfo.
/**
* Prints properties info to console.
*/
private static void printSystemPropertiesInfo() {
Map<String, Field> props = new TreeMap<>();
int maxLength = 0;
for (Class<?> cls : PROPS_CLS) {
for (Field field : cls.getFields()) {
SystemProperty ann = field.getAnnotation(SystemProperty.class);
if (ann != null) {
try {
String name = U.staticField(cls, field.getName());
maxLength = Math.max(maxLength, name.length());
props.put(name, field);
} catch (IgniteCheckedException ignored) {
// No-op.
}
}
}
}
String fmt = "%-" + maxLength + "s - %s[%s] %s.%s";
props.forEach((name, field) -> {
String deprecated = field.isAnnotationPresent(Deprecated.class) ? "[Deprecated] " : "";
SystemProperty prop = field.getAnnotation(SystemProperty.class);
String defaults = prop.defaults();
if (prop.type() == Boolean.class && defaults.isEmpty())
defaults = " Default is false.";
else if (!defaults.isEmpty())
defaults = " Default is " + defaults + '.';
X.println(format(fmt, name, deprecated, prop.type().getSimpleName(), prop.value(), defaults));
});
}
use of org.apache.ignite.SystemProperty in project ignite by apache.
the class CommandLinePrintPropertiesTest method testPrintProperties.
/**
* @throws Exception If failed.
*/
@Test
public void testPrintProperties() throws Exception {
Map<String, Field> expProps = new HashMap<>();
for (Field field : IgniteSystemProperties.class.getFields()) {
int mod = field.getModifiers();
if (isPublic(mod) && isStatic(mod) && isFinal(mod) && String.class.equals(field.getType())) {
expProps.put(U.staticField(IgniteSystemProperties.class, field.getName()), field);
SystemProperty ann = field.getAnnotation(SystemProperty.class);
assertNotNull("Field " + field.getName() + " has no SystemProperty annotation.", ann);
assertFalse(field.getName() + " value shouldn't ends with dot.", ann.value().endsWith("."));
assertFalse(field.getName() + " defaults shouldn't ends with dot.", ann.defaults().endsWith("."));
assertTrue("Ignite system property must be annotated by @" + SystemProperty.class.getSimpleName() + " [field=" + field + ']', field.isAnnotationPresent(SystemProperty.class));
}
}
for (Class<?> cls : PROPS_CLS) {
if (cls.equals(IgniteSystemProperties.class))
continue;
for (Field field : cls.getFields()) {
SystemProperty ann = field.getAnnotation(SystemProperty.class);
if (ann == null)
continue;
assertFalse(field.getName() + " value shouldn't ends with dot.", ann.value().endsWith("."));
assertFalse(field.getName() + " defaults shouldn't ends with dot.", ann.defaults().endsWith("."));
expProps.put(U.staticField(cls, field.getName()), field);
}
}
assertFalse(expProps.isEmpty());
GridJavaProcess proc = GridJavaProcess.exec(CommandLineStartup.class, PRINT_PROPS_COMMAND, log, s -> {
Matcher matcher = propPtrn.matcher(s);
if (matcher.matches()) {
String name = matcher.group(1);
boolean deprecated = !matcher.group(2).isEmpty();
String desc = matcher.group(3);
Field field = expProps.remove(name);
assertNotNull("Unexpected or duplicated property found [name=" + name + ']', field);
assertEquals(field.isAnnotationPresent(Deprecated.class), deprecated);
assertFalse("Description is empty.", desc.isEmpty());
}
}, null);
proc.getProcess().waitFor();
assertEquals(0, proc.getProcess().exitValue());
assertTrue("Not all properties printed: " + expProps, expProps.isEmpty());
}
Aggregations