}
public void testMakeShardedJobSettings() {
Key key = KeyFactory.createKey("Kind1", "value1");
MapSettings settings = new MapSettings.Builder().setWorkerQueueName("good-queue").build();
ShardedJobSettings sjSettings = settings.toShardedJobSettings("job1", key);
assertNull(sjSettings.getBackend());
assertEquals("default", sjSettings.getModule());
assertEquals("1", sjSettings.getVersion());
assertEquals("1.default.test.localhost", sjSettings.getTaskQueueTarget());
assertEquals(settings.getWorkerQueueName(), sjSettings.getQueueName());
assertEquals(getPath(settings, "job1", CONTROLLER_PATH), sjSettings.getControllerPath());
assertEquals(getPath(settings, "job1", WORKER_PATH), sjSettings.getWorkerPath());
assertEquals(makeViewerUrl(key, key), sjSettings.getPipelineStatusUrl());
assertEquals(settings.getMaxShardRetries(), sjSettings.getMaxShardRetries());
assertEquals(settings.getMaxSliceRetries(), sjSettings.getMaxSliceRetries());
settings = new MapSettings.Builder(settings).setModule(null).setBackend("b1").build();
sjSettings = settings.toShardedJobSettings("job1", key);
assertEquals("backend-hostname", sjSettings.getTaskQueueTarget());
assertEquals("b1", sjSettings.getBackend());
assertNull(sjSettings.getModule());
assertNull(sjSettings.getVersion());
settings = new MapSettings.Builder(settings).setBackend(null).setModule("module1").build();
sjSettings = settings.toShardedJobSettings("job1", key);
assertNull(sjSettings.getBackend());
assertEquals("module1", sjSettings.getModule());
assertEquals("v1", sjSettings.getVersion());
settings = new MapSettings.Builder(settings).setModule("default").build();
Environment env = ApiProxy.getCurrentEnvironment();
Environment mockEnv = EasyMock.createNiceMock(Environment.class);
EasyMock.expect(mockEnv.getModuleId()).andReturn("default").atLeastOnce();
EasyMock.expect(mockEnv.getVersionId()).andReturn("2").atLeastOnce();
EasyMock.expect(mockEnv.getAttributes()).andReturn(env.getAttributes()).anyTimes();
EasyMock.replay(mockEnv);
ApiProxy.setEnvironmentForCurrentThread(mockEnv);
// Test when current module is the same as requested module
try {
sjSettings = settings.toShardedJobSettings("job1", key);
assertNull(sjSettings.getBackend());
assertEquals("default", sjSettings.getModule());
assertEquals("2", sjSettings.getVersion());
} finally {
ApiProxy.setEnvironmentForCurrentThread(env);
}
EasyMock.verify(mockEnv);
}