Refactor to clense task name

When using Spring Boot, the id of the application context can be a colon
delimited string of values.  By default, Spring Cloud Task uses this
value as the task name.  However, when using JMX, this can cause issues.
This commit updates the SimpleTaskNameResolver to clense the colons and
replace them with underscores.

Resolves #280
This commit is contained in:
Michael Minella
2017-03-29 15:55:00 -05:00
committed by Glenn Renfro
parent fec40fd3f8
commit ac41b8c26d
2 changed files with 15 additions and 4 deletions

View File

@@ -55,7 +55,7 @@ public class SimpleTaskNameResolver implements TaskNameResolver, ApplicationCont
return configuredName;
}
else {
return context.getId();
return context.getId().replace(":", "_");
}
}
}

View File

@@ -15,13 +15,13 @@
*/
package org.springframework.cloud.task.repository.support;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import org.junit.Test;
import org.springframework.context.support.GenericApplicationContext;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
/**
* @author Michael Minella
*/
@@ -37,6 +37,17 @@ public class SimpleTaskNameResolverTests {
assertTrue(taskNameResolver.getTaskName().startsWith("org.springframework.context.support.GenericApplicationContext"));
}
@Test
public void testWithProfile() {
GenericApplicationContext context = new GenericApplicationContext();
context.setId("foo:bar");
SimpleTaskNameResolver taskNameResolver = new SimpleTaskNameResolver();
taskNameResolver.setApplicationContext(context);
assertTrue(taskNameResolver.getTaskName().startsWith("foo_bar"));
}
@Test
public void testApplicationName() {
GenericApplicationContext context = new GenericApplicationContext();