use of com.netflix.exhibitor.core.activity.ActivityQueue in project exhibitor by soabase.
the class TestRollingConfigChange method testAllDownInstances.
@Test
public void testAllDownInstances() throws Exception {
ServerList serverList = new ServerList("1:one,2:two,3:three");
RemoteInstanceRequestClient mockClient = new RemoteInstanceRequestClient() {
@Override
public void close() throws IOException {
}
@Override
public <T> T getWebResource(URI remoteUri, MediaType type, Class<T> clazz) throws Exception {
throw new Exception();
}
};
ActivityLog log = new ActivityLog(100);
ActivityQueue activityQueue = new ActivityQueue();
Exhibitor mockExhibitor = Mockito.mock(Exhibitor.class);
MonitorRunningInstance mockMonitorRunningInstance = makeMockMonitorRunningInstance();
Mockito.when(mockExhibitor.getMonitorRunningInstance()).thenReturn(mockMonitorRunningInstance);
Mockito.when(mockExhibitor.getLog()).thenReturn(log);
Mockito.when(mockExhibitor.getActivityQueue()).thenReturn(activityQueue);
Mockito.when(mockExhibitor.getThisJVMHostname()).thenReturn("_xxxx_");
Mockito.when(mockExhibitor.getRemoteInstanceRequestClient()).thenReturn(mockClient);
ConfigProvider provider = new ConfigWrapper(new AtomicLong(1));
ConfigManager manager = new ConfigManager(mockExhibitor, provider, 10, 1);
manager.start();
try {
Properties properties = new Properties();
properties.setProperty(PropertyBasedInstanceConfig.toName(StringConfigs.SERVERS_SPEC, PropertyBasedInstanceConfig.ROOT_PROPERTY_PREFIX), serverList.toSpecString());
PropertyBasedInstanceConfig config = new PropertyBasedInstanceConfig(properties, DefaultProperties.get(null));
manager.startRollingConfig(config.getRootConfig(), null);
Assert.assertFalse(manager.isRolling());
} finally {
CloseableUtils.closeQuietly(manager);
}
}
use of com.netflix.exhibitor.core.activity.ActivityQueue in project exhibitor by soabase.
the class TestRollingConfigChange method testChange.
@Test
public void testChange() throws Exception {
ServerList serverList = new ServerList("1:one,2:two,3:three");
RemoteInstanceRequestClient mockClient = new RemoteInstanceRequestClient() {
@Override
public void close() throws IOException {
}
@Override
public <T> T getWebResource(URI remoteUri, MediaType type, Class<T> clazz) throws Exception {
return clazz.cast("foo");
}
};
ActivityLog log = new ActivityLog(100);
ActivityQueue activityQueue = new ActivityQueue();
Exhibitor mockExhibitor = Mockito.mock(Exhibitor.class);
MonitorRunningInstance mockMonitorRunningInstance = makeMockMonitorRunningInstance();
Mockito.when(mockExhibitor.getMonitorRunningInstance()).thenReturn(mockMonitorRunningInstance);
Mockito.when(mockExhibitor.getLog()).thenReturn(log);
Mockito.when(mockExhibitor.getActivityQueue()).thenReturn(activityQueue);
Mockito.when(mockExhibitor.getThisJVMHostname()).thenReturn("one");
Mockito.when(mockExhibitor.getRemoteInstanceRequestClient()).thenReturn(mockClient);
final AtomicLong modified = new AtomicLong(1);
ConfigProvider provider = new ConfigProvider() {
private volatile ConfigCollection config = new PropertyBasedInstanceConfig(new Properties(), new Properties());
@Override
public void start() throws Exception {
}
@Override
public void close() throws IOException {
}
@Override
public LoadedInstanceConfig loadConfig() throws Exception {
return new LoadedInstanceConfig(config, modified.get());
}
@Override
public PseudoLock newPseudoLock() throws Exception {
return null;
}
@Override
public LoadedInstanceConfig storeConfig(ConfigCollection config, long compareVersion) throws Exception {
this.config = config;
modified.incrementAndGet();
return loadConfig();
}
};
InstanceState state = new InstanceState(serverList, InstanceStateTypes.SERVING, new RestartSignificantConfig(null));
ConfigManager manager = new ConfigManager(mockExhibitor, provider, 10);
manager.start();
try {
Properties properties = new Properties();
properties.setProperty(PropertyBasedInstanceConfig.toName(StringConfigs.SERVERS_SPEC, PropertyBasedInstanceConfig.ROOT_PROPERTY_PREFIX), serverList.toSpecString());
PropertyBasedInstanceConfig config = new PropertyBasedInstanceConfig(properties, DefaultProperties.get(null));
manager.startRollingConfig(config.getRootConfig(), null);
for (String hostname : manager.getRollingConfigState().getRollingHostNames()) {
Assert.assertTrue(manager.isRolling());
RollingReleaseState rollingState = new RollingReleaseState(state, manager.getCollection());
Assert.assertEquals(rollingState.getCurrentRollingHostname(), hostname);
Assert.assertNull(manager.getRollingConfigAdvanceAttempt());
Mockito.when(mockExhibitor.getThisJVMHostname()).thenReturn(hostname);
long lastModified = modified.get();
manager.checkRollingConfig(state);
Assert.assertTrue(modified.get() > lastModified);
}
Assert.assertFalse(manager.isRolling());
} finally {
CloseableUtils.closeQuietly(manager);
}
}
use of com.netflix.exhibitor.core.activity.ActivityQueue in project exhibitor by soabase.
the class TestRollingConfigChange method testFailedQuorum.
@Test
public void testFailedQuorum() throws Exception {
ServerList serverList = new ServerList("1:one,2:two,3:three");
RemoteInstanceRequestClient mockClient = new RemoteInstanceRequestClient() {
@Override
public void close() throws IOException {
}
@Override
public <T> T getWebResource(URI remoteUri, MediaType type, Class<T> clazz) throws Exception {
return clazz.cast("foo");
}
};
ActivityLog log = new ActivityLog(100);
ActivityQueue activityQueue = new ActivityQueue();
Exhibitor mockExhibitor = Mockito.mock(Exhibitor.class);
MonitorRunningInstance mockMonitorRunningInstance = makeMockMonitorRunningInstance();
Mockito.when(mockExhibitor.getMonitorRunningInstance()).thenReturn(mockMonitorRunningInstance);
Mockito.when(mockExhibitor.getLog()).thenReturn(log);
Mockito.when(mockExhibitor.getActivityQueue()).thenReturn(activityQueue);
Mockito.when(mockExhibitor.getThisJVMHostname()).thenReturn("one");
Mockito.when(mockExhibitor.getRemoteInstanceRequestClient()).thenReturn(mockClient);
final AtomicLong modified = new AtomicLong(1);
ConfigProvider provider = new ConfigProvider() {
private volatile ConfigCollection config = new PropertyBasedInstanceConfig(new Properties(), new Properties());
@Override
public void start() throws Exception {
}
@Override
public void close() throws IOException {
}
@Override
public LoadedInstanceConfig loadConfig() throws Exception {
return new LoadedInstanceConfig(config, modified.get());
}
@Override
public PseudoLock newPseudoLock() throws Exception {
return null;
}
@Override
public LoadedInstanceConfig storeConfig(ConfigCollection config, long compareVersion) throws Exception {
this.config = config;
modified.incrementAndGet();
return loadConfig();
}
};
InstanceState state = new InstanceState(serverList, InstanceStateTypes.NOT_SERVING, new RestartSignificantConfig(null));
final AtomicBoolean hasBeenCanceled = new AtomicBoolean(false);
ConfigManager manager = new ConfigManager(mockExhibitor, provider, 10) {
@Override
public synchronized void cancelRollingConfig(CancelMode mode) throws Exception {
super.cancelRollingConfig(mode);
hasBeenCanceled.set(true);
}
};
manager.start();
try {
Properties properties = new Properties();
properties.setProperty(PropertyBasedInstanceConfig.toName(StringConfigs.SERVERS_SPEC, PropertyBasedInstanceConfig.ROOT_PROPERTY_PREFIX), serverList.toSpecString());
PropertyBasedInstanceConfig config = new PropertyBasedInstanceConfig(properties, DefaultProperties.get(null));
manager.startRollingConfig(config.getRootConfig(), null);
String hostname = manager.getRollingConfigState().getRollingHostNames().get(0);
Assert.assertTrue(manager.isRolling());
RollingReleaseState rollingState = new RollingReleaseState(state, manager.getCollection());
Assert.assertEquals(rollingState.getCurrentRollingHostname(), hostname);
Assert.assertNull(manager.getRollingConfigAdvanceAttempt());
Mockito.when(mockExhibitor.getThisJVMHostname()).thenReturn(hostname);
for (int i = 0; i < (ConfigManager.DEFAULT_MAX_ATTEMPTS - 1); ++i) {
long lastModified = modified.get();
manager.checkRollingConfig(state);
Assert.assertFalse(modified.get() > lastModified);
Assert.assertFalse(hasBeenCanceled.get());
}
manager.checkRollingConfig(state);
Assert.assertTrue(hasBeenCanceled.get());
Assert.assertFalse(manager.isRolling());
} finally {
CloseableUtils.closeQuietly(manager);
}
}
use of com.netflix.exhibitor.core.activity.ActivityQueue in project exhibitor by soabase.
the class TestRollingConfigChange method testLongQuorumSuccess.
@Test
public void testLongQuorumSuccess() throws Exception {
ServerList serverList = new ServerList("1:one");
RemoteInstanceRequestClient mockClient = new RemoteInstanceRequestClient() {
@Override
public void close() throws IOException {
}
@Override
public <T> T getWebResource(URI remoteUri, MediaType type, Class<T> clazz) throws Exception {
throw new Exception();
}
};
ActivityLog log = new ActivityLog(100);
ActivityQueue activityQueue = new ActivityQueue();
Exhibitor mockExhibitor = Mockito.mock(Exhibitor.class);
MonitorRunningInstance mockMonitorRunningInstance = makeMockMonitorRunningInstance();
Mockito.when(mockExhibitor.getMonitorRunningInstance()).thenReturn(mockMonitorRunningInstance);
Mockito.when(mockExhibitor.getLog()).thenReturn(log);
Mockito.when(mockExhibitor.getActivityQueue()).thenReturn(activityQueue);
Mockito.when(mockExhibitor.getThisJVMHostname()).thenReturn("one");
Mockito.when(mockExhibitor.getRemoteInstanceRequestClient()).thenReturn(mockClient);
ConfigProvider provider = new ConfigWrapper(new AtomicLong(1));
Properties properties = new Properties();
properties.setProperty(PropertyBasedInstanceConfig.toName(StringConfigs.SERVERS_SPEC, PropertyBasedInstanceConfig.ROOT_PROPERTY_PREFIX), serverList.toSpecString());
properties.setProperty(PropertyBasedInstanceConfig.toName(StringConfigs.SERVERS_SPEC, PropertyBasedInstanceConfig.ROLLING_PROPERTY_PREFIX), serverList.toSpecString());
properties.setProperty(PropertyBasedInstanceConfig.PROPERTY_ROLLING_HOSTNAMES, "one");
properties.setProperty(PropertyBasedInstanceConfig.PROPERTY_ROLLING_HOSTNAMES_INDEX, "0");
PropertyBasedInstanceConfig config = new PropertyBasedInstanceConfig(properties, DefaultProperties.get(null));
provider.storeConfig(config, 0);
final int MAX_ATTEMPTS = 3;
ConfigManager manager = new ConfigManager(mockExhibitor, provider, 10, MAX_ATTEMPTS);
manager.start();
try {
InstanceState instanceState = new InstanceState(serverList, InstanceStateTypes.NOT_SERVING, new RestartSignificantConfig(null));
for (int i = 0; i < (MAX_ATTEMPTS - 1); ++i) {
manager.checkRollingConfig(instanceState);
Assert.assertTrue(manager.isRolling());
}
manager.checkRollingConfig(instanceState);
Assert.assertFalse(manager.isRolling());
} finally {
CloseableUtils.closeQuietly(manager);
}
}
use of com.netflix.exhibitor.core.activity.ActivityQueue in project exhibitor by soabase.
the class TestRollingChangeStaging method internalTest.
private void internalTest(final int attempts) throws Exception {
final Semaphore restartLatch = new Semaphore(0);
TestProcessOperations mockOperations1 = new TestProcessOperations();
TestProcessOperations mockOperations2 = new TestProcessOperations();
TestProcessOperations mockOperations3 = new TestProcessOperations();
final InstanceConfig defaultInstanceConfig = DefaultProperties.newDefaultInstanceConfig(null);
final InstanceConfig instanceConfig = new InstanceConfig() {
@Override
public String getString(StringConfigs config) {
if (config == StringConfigs.SERVERS_SPEC) {
return "1:one,2:two,3:three";
}
if ((config == StringConfigs.ZOOKEEPER_DATA_DIRECTORY) || (config == StringConfigs.ZOOKEEPER_INSTALL_DIRECTORY)) {
return "foo";
}
return defaultInstanceConfig.getString(config);
}
@Override
public int getInt(IntConfigs config) {
if (config == IntConfigs.CHECK_MS) {
return 1;
}
return defaultInstanceConfig.getInt(config);
}
};
Properties properties = DefaultProperties.getFromInstanceConfig(instanceConfig);
ConfigCollection configCollection = new PropertyBasedInstanceConfig(properties, new Properties());
LoadedInstanceConfig loadedInstanceConfig = new LoadedInstanceConfig(configCollection, 1);
final AtomicReference<LoadedInstanceConfig> providerConfig = new AtomicReference<LoadedInstanceConfig>(loadedInstanceConfig);
ConfigProvider mockConfigProvider = new ConfigProvider() {
@Override
public void start() throws Exception {
}
@Override
public LoadedInstanceConfig loadConfig() throws Exception {
return providerConfig.get();
}
@Override
public LoadedInstanceConfig storeConfig(ConfigCollection config, long compareVersion) throws Exception {
LoadedInstanceConfig loadedInstanceConfig = new LoadedInstanceConfig(config, compareVersion + 1);
providerConfig.set(loadedInstanceConfig);
return loadedInstanceConfig;
}
@Override
public PseudoLock newPseudoLock() throws Exception {
return new PseudoLock() {
@Override
public boolean lock(ActivityLog log, long maxWait, TimeUnit unit) throws Exception {
return true;
}
@Override
public void unlock() throws Exception {
}
};
}
@Override
public void close() throws IOException {
}
};
ControlPanelValues mockControlPanelValues = Mockito.mock(ControlPanelValues.class);
Mockito.when(mockControlPanelValues.isSet(Mockito.any(ControlPanelTypes.class))).thenReturn(true);
ActivityQueue activityQueue = new ActivityQueue();
final Queue<AssertionError> exceptions = Queues.newConcurrentLinkedQueue();
Exhibitor mockExhibitor1 = Mockito.mock(Exhibitor.class, Mockito.RETURNS_MOCKS);
Mockito.when(mockExhibitor1.getActivityQueue()).thenReturn(activityQueue);
ConfigManager configManager1 = new TestConfigManager(mockExhibitor1, mockConfigProvider);
Mockito.when(mockExhibitor1.getConfigManager()).thenReturn(configManager1);
MonitorRunningInstance monitorRunningInstance1 = new MockMonitorRunningInstance(mockExhibitor1, providerConfig, "one", restartLatch, exceptions);
Mockito.when(mockExhibitor1.getMonitorRunningInstance()).thenReturn(monitorRunningInstance1);
Mockito.when(mockExhibitor1.getThisJVMHostname()).thenReturn("one");
Mockito.when(mockExhibitor1.getProcessOperations()).thenReturn(mockOperations1);
Mockito.when(mockExhibitor1.getControlPanelValues()).thenReturn(mockControlPanelValues);
Exhibitor mockExhibitor2 = Mockito.mock(Exhibitor.class, Mockito.RETURNS_MOCKS);
Mockito.when(mockExhibitor2.getActivityQueue()).thenReturn(activityQueue);
ConfigManager configManager2 = new TestConfigManager(mockExhibitor2, mockConfigProvider);
Mockito.when(mockExhibitor2.getConfigManager()).thenReturn(configManager2);
MonitorRunningInstance monitorRunningInstance2 = new MockMonitorRunningInstance(mockExhibitor2, providerConfig, "two", restartLatch, exceptions);
Mockito.when(mockExhibitor2.getMonitorRunningInstance()).thenReturn(monitorRunningInstance2);
Mockito.when(mockExhibitor2.getThisJVMHostname()).thenReturn("two");
Mockito.when(mockExhibitor2.getProcessOperations()).thenReturn(mockOperations2);
Mockito.when(mockExhibitor2.getControlPanelValues()).thenReturn(mockControlPanelValues);
Exhibitor mockExhibitor3 = Mockito.mock(Exhibitor.class, Mockito.RETURNS_MOCKS);
Mockito.when(mockExhibitor3.getActivityQueue()).thenReturn(activityQueue);
ConfigManager configManager3 = new TestConfigManager(mockExhibitor3, mockConfigProvider);
Mockito.when(mockExhibitor3.getConfigManager()).thenReturn(configManager3);
MonitorRunningInstance monitorRunningInstance3 = new MockMonitorRunningInstance(mockExhibitor3, providerConfig, "three", restartLatch, exceptions);
Mockito.when(mockExhibitor3.getMonitorRunningInstance()).thenReturn(monitorRunningInstance3);
Mockito.when(mockExhibitor3.getThisJVMHostname()).thenReturn("three");
Mockito.when(mockExhibitor3.getProcessOperations()).thenReturn(mockOperations3);
Mockito.when(mockExhibitor3.getControlPanelValues()).thenReturn(mockControlPanelValues);
try {
activityQueue.start();
configManager1.start();
configManager2.start();
configManager3.start();
monitorRunningInstance1.start();
monitorRunningInstance2.start();
monitorRunningInstance3.start();
Thread.sleep(1000);
for (int i = 0; i < attempts; ++i) {
Assert.assertEquals(restartLatch.availablePermits(), 0);
final int index = i;
InstanceConfig changedInstanceConfig = new InstanceConfig() {
@Override
public String getString(StringConfigs config) {
if (config == StringConfigs.LOG4J_PROPERTIES) {
return "something different " + index;
}
return instanceConfig.getString(config);
}
@Override
public int getInt(IntConfigs config) {
return instanceConfig.getInt(config);
}
};
configManager1.startRollingConfig(changedInstanceConfig, "one");
Assert.assertTrue(restartLatch.tryAcquire(1, 10, TimeUnit.SECONDS));
if (exceptions.size() > 0) {
for (AssertionError assertionError : exceptions) {
assertionError.printStackTrace();
}
Assert.fail("Failed restart assertions");
}
}
} finally {
CloseableUtils.closeQuietly(monitorRunningInstance3);
CloseableUtils.closeQuietly(monitorRunningInstance2);
CloseableUtils.closeQuietly(monitorRunningInstance1);
CloseableUtils.closeQuietly(configManager3);
CloseableUtils.closeQuietly(configManager2);
CloseableUtils.closeQuietly(configManager1);
CloseableUtils.closeQuietly(activityQueue);
}
}
Aggregations