use of org.apache.helix.msdcommon.mock.MockMetadataStoreDirectoryServer in project helix by apache.
the class TestMultiZkHelixJavaApis method beforeClass.
@BeforeClass
public void beforeClass() throws Exception {
// Create 3 in-memory zookeepers and routing mapping
for (int i = 0; i < NUM_ZK; i++) {
String zkAddress = ZK_PREFIX + (ZK_START_PORT + i);
ZK_SERVER_MAP.put(zkAddress, TestHelper.startZkServer(zkAddress));
ZK_CLIENT_MAP.put(zkAddress, DedicatedZkClientFactory.getInstance().buildZkClient(new HelixZkClient.ZkConnectionConfig(zkAddress), new HelixZkClient.ZkClientConfig().setZkSerializer(new ZNRecordSerializer())));
// One cluster per ZkServer created
_rawRoutingData.put(zkAddress, Collections.singletonList("/" + CLUSTER_LIST.get(i)));
}
// Create a Mock MSDS
final String msdsHostName = "localhost";
final int msdsPort = 11117;
final String msdsNamespace = "multiZkTest";
_msdsEndpoint = "http://" + msdsHostName + ":" + msdsPort + "/admin/v2/namespaces/" + msdsNamespace;
_msds = new MockMetadataStoreDirectoryServer(msdsHostName, msdsPort, msdsNamespace, _rawRoutingData);
_msds.startServer();
// Save previously-set system configs
String prevMultiZkEnabled = System.getProperty(SystemPropertyKeys.MULTI_ZK_ENABLED);
String prevMsdsServerEndpoint = System.getProperty(MetadataStoreRoutingConstants.MSDS_SERVER_ENDPOINT_KEY);
if (prevMultiZkEnabled != null) {
_configStore.put(SystemPropertyKeys.MULTI_ZK_ENABLED, prevMultiZkEnabled);
}
if (prevMsdsServerEndpoint != null) {
_configStore.put(MetadataStoreRoutingConstants.MSDS_SERVER_ENDPOINT_KEY, prevMsdsServerEndpoint);
}
// Turn on multiZk mode in System config
System.setProperty(SystemPropertyKeys.MULTI_ZK_ENABLED, "true");
// MSDS endpoint: http://localhost:11117/admin/v2/namespaces/multiZkTest
System.setProperty(MetadataStoreRoutingConstants.MSDS_SERVER_ENDPOINT_KEY, _msdsEndpoint);
// Routing data may be set by other tests using the same endpoint; reset() for good measure
RoutingDataManager.getInstance().reset();
// Create a FederatedZkClient for admin work
_zkClient = new FederatedZkClient(new RealmAwareZkClient.RealmAwareZkConnectionConfig.Builder().build(), new RealmAwareZkClient.RealmAwareZkClientConfig());
}
use of org.apache.helix.msdcommon.mock.MockMetadataStoreDirectoryServer in project helix by apache.
the class RealmAwareZkClientTestBase method beforeClass.
@BeforeClass
public void beforeClass() throws IOException, InvalidRoutingDataException {
// Create a mock MSDS so that HttpRoutingDataReader could fetch the routing data
if (_msdsServer == null) {
// Do not create again if Mock MSDS server has already been created by other tests
_msdsServer = new MockMetadataStoreDirectoryServer(MSDS_HOSTNAME, MSDS_PORT, MSDS_NAMESPACE, TestConstants.FAKE_ROUTING_DATA);
_msdsServer.startServer();
}
// Register the MSDS endpoint as a System variable
String msdsEndpoint = "http://" + MSDS_HOSTNAME + ":" + MSDS_PORT + "/admin/v2/namespaces/" + MSDS_NAMESPACE;
System.setProperty(MetadataStoreRoutingConstants.MSDS_SERVER_ENDPOINT_KEY, msdsEndpoint);
}
use of org.apache.helix.msdcommon.mock.MockMetadataStoreDirectoryServer in project helix by apache.
the class TestRoutingDataManager method testStaticMapping.
/**
* Test that the static methods in HttpRoutingDataReader returns consistent results even though MSDS's data have been updated.
*/
@Test(dependsOnMethods = "testGetMetadataStoreRoutingData")
public void testStaticMapping() throws IOException, InvalidRoutingDataException {
// Modify routing data
String newRealm = "newRealm";
Map<String, Collection<String>> newRoutingData = new HashMap<>(TestConstants.FAKE_ROUTING_DATA);
newRoutingData.put(newRealm, ImmutableSet.of("/newKey"));
// Kill MSDS and restart with a new mapping
_msdsServer.stopServer();
_msdsServer = new MockMetadataStoreDirectoryServer(HOST, PORT, NAMESPACE, newRoutingData);
_msdsServer.startServer();
// HttpRoutingDataReader should still return old data because it's static
// Make sure the results don't contain the new realm
Map<String, List<String>> rawRoutingData = RoutingDataManager.getInstance().getRawRoutingData();
Assert.assertFalse(rawRoutingData.containsKey(newRealm));
// Remove newRealm and check for equality
newRoutingData.remove(newRealm);
Assert.assertEquals(rawRoutingData.keySet(), TestConstants.FAKE_ROUTING_DATA.keySet());
TestConstants.FAKE_ROUTING_DATA.forEach((realm, keys) -> Assert.assertEquals(new HashSet(rawRoutingData.get(realm)), new HashSet(keys)));
MetadataStoreRoutingData data = RoutingDataManager.getInstance().getMetadataStoreRoutingData();
Map<String, String> allMappings = data.getAllMappingUnderPath("/");
Map<String, Set<String>> groupedMappings = allMappings.entrySet().stream().collect(Collectors.groupingBy(Map.Entry::getValue, Collectors.mapping(Map.Entry::getKey, Collectors.toSet())));
Assert.assertFalse(groupedMappings.containsKey(newRealm));
}
use of org.apache.helix.msdcommon.mock.MockMetadataStoreDirectoryServer in project helix by apache.
the class TestTaskStateModelFactory method testZkClientCreationMultiZk.
@Test
public void testZkClientCreationMultiZk() throws Exception {
MockParticipantManager anyParticipantManager = _participants[0];
InstanceConfig instanceConfig = InstanceConfig.toInstanceConfig(anyParticipantManager.getInstanceName());
instanceConfig.setTargetTaskThreadPoolSize(TEST_TARGET_TASK_THREAD_POOL_SIZE);
anyParticipantManager.getConfigAccessor().setInstanceConfig(anyParticipantManager.getClusterName(), anyParticipantManager.getInstanceName(), instanceConfig);
// Start a msds server
// TODO: Refactor all MSDS_SERVER_ENDPOINT creation in system property to one place.
// Any test that modifies MSDS_SERVER_ENDPOINT system property and accesses
// HttpRoutingDataReader (ex. TestMultiZkHelixJavaApis and this test) will cause the
// MSDS_SERVER_ENDPOINT system property to be recorded as final in HttpRoutingDataReader; that
// means any test class that satisfies the aforementioned condition and is executed first gets
// to "decide" the default msds endpoint. The only workaround is for all these test classes to
// use the same default msds endpoint.
final String msdsHostName = "localhost";
final int msdsPort = 11117;
final String msdsNamespace = "multiZkTest";
Map<String, Collection<String>> routingData = new HashMap<>();
routingData.put(ZK_ADDR, Collections.singletonList("/" + anyParticipantManager.getClusterName()));
MockMetadataStoreDirectoryServer msds = new MockMetadataStoreDirectoryServer(msdsHostName, msdsPort, msdsNamespace, routingData);
msds.startServer();
// Save previously-set system configs
String prevMultiZkEnabled = System.getProperty(SystemPropertyKeys.MULTI_ZK_ENABLED);
String prevMsdsServerEndpoint = System.getProperty(MetadataStoreRoutingConstants.MSDS_SERVER_ENDPOINT_KEY);
// Turn on multiZk mode in System config
System.setProperty(SystemPropertyKeys.MULTI_ZK_ENABLED, "true");
// MSDS endpoint: http://localhost:11117/admin/v2/namespaces/testTaskStateModelFactory
String testMSDSServerEndpointKey = "http://" + msdsHostName + ":" + msdsPort + "/admin/v2/namespaces/" + msdsNamespace;
System.setProperty(MetadataStoreRoutingConstants.MSDS_SERVER_ENDPOINT_KEY, testMSDSServerEndpointKey);
RoutingDataManager.getInstance().reset();
verifyThreadPoolSizeAndZkClientClass(anyParticipantManager, TEST_TARGET_TASK_THREAD_POOL_SIZE, FederatedZkClient.class);
// Turn off multiZk mode in System config, and remove zkAddress
System.setProperty(SystemPropertyKeys.MULTI_ZK_ENABLED, "false");
ZKHelixManager participantManager = Mockito.spy(anyParticipantManager);
when(participantManager.getMetadataStoreConnectionString()).thenReturn(null);
verifyThreadPoolSizeAndZkClientClass(participantManager, TEST_TARGET_TASK_THREAD_POOL_SIZE, FederatedZkClient.class);
// Test no connection config case
when(participantManager.getRealmAwareZkConnectionConfig()).thenReturn(null);
verifyThreadPoolSizeAndZkClientClass(participantManager, TEST_TARGET_TASK_THREAD_POOL_SIZE, FederatedZkClient.class);
// Remove server endpoint key and use connection config to specify endpoint
System.clearProperty(SystemPropertyKeys.MSDS_SERVER_ENDPOINT_KEY);
RealmAwareZkClient.RealmAwareZkConnectionConfig connectionConfig = new RealmAwareZkClient.RealmAwareZkConnectionConfig.Builder().setRealmMode(RealmAwareZkClient.RealmMode.MULTI_REALM).setRoutingDataSourceEndpoint(testMSDSServerEndpointKey).setRoutingDataSourceType(RoutingDataReaderType.HTTP.name()).build();
when(participantManager.getRealmAwareZkConnectionConfig()).thenReturn(connectionConfig);
verifyThreadPoolSizeAndZkClientClass(participantManager, TEST_TARGET_TASK_THREAD_POOL_SIZE, FederatedZkClient.class);
// Restore system properties
if (prevMultiZkEnabled == null) {
System.clearProperty(SystemPropertyKeys.MULTI_ZK_ENABLED);
} else {
System.setProperty(SystemPropertyKeys.MULTI_ZK_ENABLED, prevMultiZkEnabled);
}
if (prevMsdsServerEndpoint == null) {
System.clearProperty(SystemPropertyKeys.MSDS_SERVER_ENDPOINT_KEY);
} else {
System.setProperty(SystemPropertyKeys.MSDS_SERVER_ENDPOINT_KEY, prevMsdsServerEndpoint);
}
msds.stopServer();
}
Aggregations