forked from soabase/exhibitor
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
work on automatic instance management continues
- Loading branch information
Showing
9 changed files
with
451 additions
and
390 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
201 changes: 201 additions & 0 deletions
201
exhibitor-core/src/test/java/com/netflix/exhibitor/core/automanage/MockConfigProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,201 @@ | ||
/* | ||
* Copyright 2012 Netflix, Inc. | ||
* | ||
* 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. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.netflix.exhibitor.core.automanage; | ||
|
||
import com.netflix.exhibitor.core.activity.ActivityLog; | ||
import com.netflix.exhibitor.core.config.ConfigCollection; | ||
import com.netflix.exhibitor.core.config.ConfigProvider; | ||
import com.netflix.exhibitor.core.config.InstanceConfig; | ||
import com.netflix.exhibitor.core.config.IntConfigs; | ||
import com.netflix.exhibitor.core.config.LoadedInstanceConfig; | ||
import com.netflix.exhibitor.core.config.PropertyBasedInstanceConfig; | ||
import com.netflix.exhibitor.core.config.PseudoLock; | ||
import com.netflix.exhibitor.core.config.RollingConfigState; | ||
import com.netflix.exhibitor.core.config.StringConfigs; | ||
import java.io.IOException; | ||
import java.util.Properties; | ||
import java.util.concurrent.TimeUnit; | ||
|
||
class MockConfigProvider implements ConfigProvider | ||
{ | ||
private volatile ConfigCollection collection = new PropertyBasedInstanceConfig(new Properties(), new Properties()); | ||
|
||
void setConfig(final StringConfigs type, final String value) | ||
{ | ||
final InstanceConfig config = collection.getRootConfig(); | ||
final InstanceConfig newConfig = new InstanceConfig() | ||
{ | ||
@Override | ||
public String getString(StringConfigs configType) | ||
{ | ||
if ( configType == type ) | ||
{ | ||
return value; | ||
} | ||
return config.getString(configType); | ||
} | ||
|
||
@Override | ||
public int getInt(IntConfigs configType) | ||
{ | ||
return config.getInt(configType); | ||
} | ||
}; | ||
collection = new ConfigCollection() | ||
{ | ||
@Override | ||
public InstanceConfig getConfigForThisInstance(String hostname) | ||
{ | ||
return getRootConfig(); | ||
} | ||
|
||
@Override | ||
public InstanceConfig getRootConfig() | ||
{ | ||
return newConfig; | ||
} | ||
|
||
@Override | ||
public InstanceConfig getRollingConfig() | ||
{ | ||
return null; | ||
} | ||
|
||
@Override | ||
public boolean isRolling() | ||
{ | ||
return false; | ||
} | ||
|
||
@Override | ||
public RollingConfigState getRollingConfigState() | ||
{ | ||
return null; | ||
} | ||
}; | ||
} | ||
|
||
void setConfig(final IntConfigs type, final int value) | ||
{ | ||
final InstanceConfig config = collection.getRootConfig(); | ||
final InstanceConfig newConfig = new InstanceConfig() | ||
{ | ||
@Override | ||
public String getString(StringConfigs configType) | ||
{ | ||
return config.getString(configType); | ||
} | ||
|
||
@Override | ||
public int getInt(IntConfigs configType) | ||
{ | ||
if ( configType == type ) | ||
{ | ||
return value; | ||
} | ||
return config.getInt(configType); | ||
} | ||
}; | ||
collection = new ConfigCollection() | ||
{ | ||
@Override | ||
public InstanceConfig getConfigForThisInstance(String hostname) | ||
{ | ||
return getRootConfig(); | ||
} | ||
|
||
@Override | ||
public InstanceConfig getRootConfig() | ||
{ | ||
return newConfig; | ||
} | ||
|
||
@Override | ||
public InstanceConfig getRollingConfig() | ||
{ | ||
return null; | ||
} | ||
|
||
@Override | ||
public boolean isRolling() | ||
{ | ||
return false; | ||
} | ||
|
||
@Override | ||
public RollingConfigState getRollingConfigState() | ||
{ | ||
return null; | ||
} | ||
}; | ||
} | ||
|
||
@Override | ||
public void start() throws Exception | ||
{ | ||
} | ||
|
||
@Override | ||
public LoadedInstanceConfig loadConfig() throws Exception | ||
{ | ||
return new LoadedInstanceConfig(collection, 0) | ||
{ | ||
@Override | ||
public ConfigCollection getConfig() | ||
{ | ||
return collection; | ||
} | ||
}; | ||
} | ||
|
||
@Override | ||
public LoadedInstanceConfig storeConfig(ConfigCollection config, long compareVersion) throws Exception | ||
{ | ||
collection = config; | ||
return new LoadedInstanceConfig(config, compareVersion) | ||
{ | ||
@Override | ||
public ConfigCollection getConfig() | ||
{ | ||
return collection; | ||
} | ||
}; | ||
} | ||
|
||
@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 | ||
{ | ||
} | ||
} |
Oops, something went wrong.