Java Code Examples for org.apache.helix.model.ExternalView#setStateMap()
The following examples show how to use
org.apache.helix.model.ExternalView#setStateMap() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TerrapinClientTest.java From terrapin with Apache License 2.0 | 6 votes |
private ViewInfo createViewInfo(Map<String, List<String>> partitionHostMap) { ExternalView externalView = new ExternalView(RESOURCE); for (Map.Entry<String, List<String>> entry : partitionHostMap.entrySet()) { String host = entry.getKey(); for (String partition : entry.getValue()) { String partitionInHelix = RESOURCE + "$" + partition; Map<String, String> stateMap = externalView.getStateMap(partitionInHelix); if (stateMap == null) { stateMap = Maps.newHashMap(); stateMap.put(host, "ONLINE"); externalView.setStateMap(partitionInHelix, stateMap); } else { stateMap.put(host, "ONLINE"); } } } return new ViewInfo(externalView); }
Example 2
Source File: TestInstanceValidationUtil.java From helix with Apache License 2.0 | 6 votes |
@Test public void TestIsInstanceStable_true() { String resource = "db"; Mock mock = new Mock(); ClusterConfig clusterConfig = new ClusterConfig(TEST_CLUSTER); clusterConfig.setPersistIntermediateAssignment(true); doReturn(clusterConfig).when(mock.dataAccessor) .getProperty(argThat(new PropertyKeyArgument(PropertyType.CONFIGS))); doReturn(ImmutableList.of(resource)).when(mock.dataAccessor) .getChildNames(argThat(new PropertyKeyArgument(PropertyType.IDEALSTATES))); IdealState idealState = mock(IdealState.class); when(idealState.isEnabled()).thenReturn(Boolean.TRUE); when(idealState.getPartitionSet()).thenReturn(ImmutableSet.of("db0")); when(idealState.getInstanceStateMap("db0")) .thenReturn(ImmutableMap.of(TEST_INSTANCE, "Master")); idealState.setInstanceStateMap("db0", ImmutableMap.of(TEST_INSTANCE, "Master")); doReturn(idealState).when(mock.dataAccessor) .getProperty(argThat(new PropertyKeyArgument(PropertyType.IDEALSTATES))); ExternalView externalView = new ExternalView(resource); externalView.setStateMap("db0", ImmutableMap.of(TEST_INSTANCE, "Master")); doReturn(externalView).when(mock.dataAccessor) .getProperty(argThat(new PropertyKeyArgument(PropertyType.EXTERNALVIEW))); boolean result = InstanceValidationUtil.isInstanceStable(mock.dataAccessor, TEST_INSTANCE); Assert.assertTrue(result); }
Example 3
Source File: TestInstanceValidationUtil.java From helix with Apache License 2.0 | 6 votes |
@Test(description = "IdealState: slave state, ExternalView:Master state") public void TestIsInstanceStable_false() { String resource = "db"; Mock mock = new Mock(); ClusterConfig clusterConfig = new ClusterConfig(TEST_CLUSTER); clusterConfig.setPersistIntermediateAssignment(true); doReturn(clusterConfig).when(mock.dataAccessor) .getProperty(argThat(new PropertyKeyArgument(PropertyType.CONFIGS))); doReturn(ImmutableList.of(resource)).when(mock.dataAccessor) .getChildNames(argThat(new PropertyKeyArgument(PropertyType.IDEALSTATES))); IdealState idealState = mock(IdealState.class); when(idealState.isEnabled()).thenReturn(true); when(idealState.getPartitionSet()).thenReturn(ImmutableSet.of("db0")); when(idealState.getInstanceStateMap("db0")).thenReturn(ImmutableMap.of(TEST_INSTANCE, "slave")); when(idealState.isValid()).thenReturn(true); when(idealState.getStateModelDefRef()).thenReturn("MasterSlave"); doReturn(idealState).when(mock.dataAccessor) .getProperty(argThat(new PropertyKeyArgument(PropertyType.IDEALSTATES))); ExternalView externalView = new ExternalView(resource); externalView.setStateMap("db0", ImmutableMap.of(TEST_INSTANCE, "Master")); doReturn(externalView).when(mock.dataAccessor) .getProperty(argThat(new PropertyKeyArgument(PropertyType.EXTERNALVIEW))); boolean result = InstanceValidationUtil.isInstanceStable(mock.dataAccessor, TEST_INSTANCE); Assert.assertFalse(result); }
Example 4
Source File: FileStatusServletTest.java From terrapin with Apache License 2.0 | 5 votes |
@Before public void setUp() { externalView = new ExternalView("resource"); externalView.setStateMap("resource_1", new ImmutableMap.Builder() .put("host1", "OFFLINE") .put("host2", "ONLINE") .put("host3", "ONLINE").build()); externalView.setStateMap("resource$2", new ImmutableMap.Builder() .put("host1", "OFFLINE") .put("host2", "OFFLINE").build()); externalView.setStateMap("resource$3", new ImmutableMap.Builder() .put("host1", "ONLINE") .put("host2", "OFFLINE").build()); viewInfo = new ViewInfo(externalView); }
Example 5
Source File: ViewInfoTest.java From terrapin with Apache License 2.0 | 5 votes |
@Before public void setUp() { externalView = new ExternalView("resource"); externalView.setStateMap("resource_1", new ImmutableMap.Builder() .put("host1", "OFFLINE") .put("host2", "ONLINE") .put("host3", "ONLINE").build()); externalView.setStateMap("resource$2", new ImmutableMap.Builder() .put("host1", "OFFLINE") .put("host2", "OFFLINE").build()); externalView.setStateMap("resource$3", new ImmutableMap.Builder() .put("host1", "ONLINE") .put("host2", "OFFLINE").build()); viewInfo = new ViewInfo(externalView); }