@Test public void testSerDe() throws IOException { Map<String, Object> mappings = new HashMap<>(); Map<String, Object> defaultAppMappings = new HashMap<>(); defaultAppMappings.put(StreamJobClusterMap.DEFAULT_STREAM_KEY, "SharedPushEventSource"); defaultAppMappings.put("testEventStream", "TestPushEventSource"); mappings.put(AppJobClustersMap.DEFAULT_APP_KEY, defaultAppMappings); Map<String, Object> customAppMappings = new HashMap<>(); customAppMappings.put("customEventStream", "CustomPushEventSource"); customAppMappings.put(StreamJobClusterMap.DEFAULT_STREAM_KEY, "CustomDefaultPushEventSource"); mappings.put("custom", customAppMappings); AppJobClustersMap mapV1 = new AppJobClustersMap(AppJobClustersMap.VERSION_1, System.currentTimeMillis(), mappings); assertEquals("SharedPushEventSource", mapV1.getStreamJobClusterMap(AppJobClustersMap.DEFAULT_APP_KEY).getJobCluster(StreamJobClusterMap.DEFAULT_STREAM_KEY)); assertEquals("SharedPushEventSource", mapV1.getStreamJobClusterMap(AppJobClustersMap.DEFAULT_APP_KEY).getJobCluster("AnyRandomStream")); assertEquals("TestPushEventSource", mapV1.getStreamJobClusterMap(AppJobClustersMap.DEFAULT_APP_KEY).getJobCluster("testEventStream")); StreamJobClusterMap customStreamJCMap = mapV1.getStreamJobClusterMap("custom"); System.out.println("custom app mapping: " + customStreamJCMap); assertTrue(customStreamJCMap.getStreamJobClusterMap().size() == 2); assertTrue(customStreamJCMap.getStreamJobClusterMap().containsKey(StreamJobClusterMap.DEFAULT_STREAM_KEY)); assertFalse(customStreamJCMap.getStreamJobClusterMap().containsKey("testEventStream")); assertTrue(customStreamJCMap.getStreamJobClusterMap().containsKey("customEventStream")); assertEquals("CustomDefaultPushEventSource", customStreamJCMap.getJobCluster(StreamJobClusterMap.DEFAULT_STREAM_KEY)); assertEquals("CustomDefaultPushEventSource", customStreamJCMap.getJobCluster("AnyRandomStreamName")); assertEquals("CustomDefaultPushEventSource", customStreamJCMap.getJobCluster("testEventStream")); assertEquals("CustomPushEventSource", customStreamJCMap.getJobCluster("customEventStream")); ObjectMapper mapper = new ObjectMapper(); String mappingStr = mapper.writeValueAsString(mapV1); System.out.println("input mappings " + mappingStr); AppJobClustersMap appJobClustersMap = mapper.readValue(mappingStr, AppJobClustersMap.class); System.out.println("parsed mappings " + appJobClustersMap); assertEquals(mapV1, appJobClustersMap); }
@JsonIgnore public StreamJobClusterMap getStreamJobClusterMap(final String appName) { Map<String, String> mappings = this.mappings.getOrDefault(appName, defaultStreamJobClusterMap()); return new StreamJobClusterMap(appName, mappings); }
AppJobClustersMap { @JsonIgnore public StreamJobClusterMap getStreamJobClusterMap(final String appName) { Map<String, String> mappings = this.mappings.getOrDefault(appName, defaultStreamJobClusterMap()); return new StreamJobClusterMap(appName, mappings); } }
AppJobClustersMap { @JsonIgnore public StreamJobClusterMap getStreamJobClusterMap(final String appName) { Map<String, String> mappings = this.mappings.getOrDefault(appName, defaultStreamJobClusterMap()); return new StreamJobClusterMap(appName, mappings); } @JsonCreator @JsonIgnoreProperties(ignoreUnknown = true)  AppJobClustersMap(@JsonProperty("version") String version,
                             @JsonProperty("timestamp") long ts,
                             @JsonProperty("mappings") Map<String, Object> mappings);  AppJobClustersMap(); }
AppJobClustersMap { @JsonIgnore public StreamJobClusterMap getStreamJobClusterMap(final String appName) { Map<String, String> mappings = this.mappings.getOrDefault(appName, defaultStreamJobClusterMap()); return new StreamJobClusterMap(appName, mappings); } @JsonCreator @JsonIgnoreProperties(ignoreUnknown = true)  AppJobClustersMap(@JsonProperty("version") String version,
                             @JsonProperty("timestamp") long ts,
                             @JsonProperty("mappings") Map<String, Object> mappings);  AppJobClustersMap(); @JsonIgnore static T checkNotNull(T obj, String name); String getVersion(); Map<String, Map<String, String>> getMappings(); long getTimestamp(); @JsonIgnore StreamJobClusterMap getStreamJobClusterMap(final String appName); @JsonIgnore AppJobClustersMap getFilteredAppJobClustersMap(final List<String> apps); @Override boolean equals(Object o); @Override int hashCode(); @Override String toString(); }
AppJobClustersMap { @JsonIgnore public StreamJobClusterMap getStreamJobClusterMap(final String appName) { Map<String, String> mappings = this.mappings.getOrDefault(appName, defaultStreamJobClusterMap()); return new StreamJobClusterMap(appName, mappings); } @JsonCreator @JsonIgnoreProperties(ignoreUnknown = true)  AppJobClustersMap(@JsonProperty("version") String version,
                             @JsonProperty("timestamp") long ts,
                             @JsonProperty("mappings") Map<String, Object> mappings);  AppJobClustersMap(); @JsonIgnore static T checkNotNull(T obj, String name); String getVersion(); Map<String, Map<String, String>> getMappings(); long getTimestamp(); @JsonIgnore StreamJobClusterMap getStreamJobClusterMap(final String appName); @JsonIgnore AppJobClustersMap getFilteredAppJobClustersMap(final List<String> apps); @Override boolean equals(Object o); @Override int hashCode(); @Override String toString(); static final String VERSION_1; static final String DEFAULT_APP_KEY; }