34
34
public class FakeLocalMetadataStore {
35
35
private static final Logger log = LoggerFactory .getLogger (FakeLocalMetadataStore .class );
36
36
37
- private static ConcurrentHashMap <String , ConcurrentHashMap <String , String >> allTopics = new ConcurrentHashMap <>();
38
- private static ConcurrentHashMap <String , Vector <AclBinding >> allAcls = new ConcurrentHashMap <>();
37
+ private static final ConcurrentHashMap <String , ConcurrentHashMap <String , String >> ALL_TOPICS = new ConcurrentHashMap <>();
38
+ private static final ConcurrentHashMap <String , Vector <AclBinding >> ALL_ACLS = new ConcurrentHashMap <>();
39
39
40
40
/**
41
41
* Add topic to allTopics.
@@ -44,7 +44,7 @@ public class FakeLocalMetadataStore {
44
44
public static void addTopicToLocalMetadataStore (NewTopic newTopic ) {
45
45
ConcurrentHashMap <String , String > configs = new ConcurrentHashMap <>(newTopic .configs ());
46
46
configs .putIfAbsent ("partitions" , String .valueOf (newTopic .numPartitions ()));
47
- allTopics .putIfAbsent (newTopic .name (), configs );
47
+ ALL_TOPICS .putIfAbsent (newTopic .name (), configs );
48
48
}
49
49
50
50
/**
@@ -53,9 +53,9 @@ public static void addTopicToLocalMetadataStore(NewTopic newTopic) {
53
53
* @param newPartitionCount new partition count.
54
54
*/
55
55
public static void updatePartitionCount (String topic , int newPartitionCount ) {
56
- ConcurrentHashMap <String , String > configs = FakeLocalMetadataStore .allTopics .getOrDefault (topic , new ConcurrentHashMap <>());
56
+ ConcurrentHashMap <String , String > configs = FakeLocalMetadataStore .ALL_TOPICS .getOrDefault (topic , new ConcurrentHashMap <>());
57
57
configs .compute ("partitions" , (key , value ) -> String .valueOf (newPartitionCount ));
58
- FakeLocalMetadataStore .allTopics .putIfAbsent (topic , configs );
58
+ FakeLocalMetadataStore .ALL_TOPICS .putIfAbsent (topic , configs );
59
59
}
60
60
61
61
/**
@@ -64,7 +64,7 @@ public static void updatePartitionCount(String topic, int newPartitionCount) {
64
64
* @param newConfig topic config
65
65
*/
66
66
public static void updateTopicConfig (String topic , Config newConfig ) {
67
- ConcurrentHashMap <String , String > topicConfigs = FakeLocalMetadataStore .allTopics .getOrDefault (topic , new ConcurrentHashMap <>());
67
+ ConcurrentHashMap <String , String > topicConfigs = FakeLocalMetadataStore .ALL_TOPICS .getOrDefault (topic , new ConcurrentHashMap <>());
68
68
newConfig .entries ().stream ().forEach (configEntry -> {
69
69
if (configEntry .name () != null ) {
70
70
if (configEntry .value () != null ) {
@@ -75,7 +75,7 @@ public static void updateTopicConfig(String topic, Config newConfig) {
75
75
}
76
76
}
77
77
});
78
- FakeLocalMetadataStore .allTopics .putIfAbsent (topic , topicConfigs );
78
+ FakeLocalMetadataStore .ALL_TOPICS .putIfAbsent (topic , topicConfigs );
79
79
}
80
80
81
81
/**
@@ -84,7 +84,7 @@ public static void updateTopicConfig(String topic, Config newConfig) {
84
84
* @return true if topic name is a key in allTopics
85
85
*/
86
86
public static Boolean containsTopic (String topic ) {
87
- return allTopics .containsKey (topic );
87
+ return ALL_TOPICS .containsKey (topic );
88
88
}
89
89
90
90
/**
@@ -93,7 +93,7 @@ public static Boolean containsTopic(String topic) {
93
93
* @return topic configurations.
94
94
*/
95
95
public static Map <String , String > topicConfig (String topic ) {
96
- return allTopics .getOrDefault (topic , new ConcurrentHashMap <>());
96
+ return ALL_TOPICS .getOrDefault (topic , new ConcurrentHashMap <>());
97
97
}
98
98
99
99
/**
@@ -102,7 +102,7 @@ public static Map<String, String> topicConfig(String topic) {
102
102
* @return {@link List<AclBinding>}
103
103
*/
104
104
public static List <AclBinding > aclBindings (String aclPrinciple ) {
105
- return FakeLocalMetadataStore .allAcls .getOrDefault ("User:" + aclPrinciple , new Vector <>());
105
+ return FakeLocalMetadataStore .ALL_ACLS .getOrDefault ("User:" + aclPrinciple , new Vector <>());
106
106
}
107
107
108
108
/**
@@ -111,16 +111,16 @@ public static List<AclBinding> aclBindings(String aclPrinciple) {
111
111
* @param aclBinding {@link AclBinding}
112
112
*/
113
113
public static void addACLs (String principal , AclBinding aclBinding ) {
114
- Vector <AclBinding > aclBindings = FakeLocalMetadataStore .allAcls .getOrDefault (principal , new Vector <>());
114
+ Vector <AclBinding > aclBindings = FakeLocalMetadataStore .ALL_ACLS .getOrDefault (principal , new Vector <>());
115
115
aclBindings .add (aclBinding );
116
- FakeLocalMetadataStore .allAcls .putIfAbsent (principal , aclBindings );
116
+ FakeLocalMetadataStore .ALL_ACLS .putIfAbsent (principal , aclBindings );
117
117
}
118
118
119
119
/**
120
120
* clear allTopics and allAcls.
121
121
*/
122
122
public static void clear () {
123
- allTopics .clear ();
124
- allAcls .clear ();
123
+ ALL_TOPICS .clear ();
124
+ ALL_ACLS .clear ();
125
125
}
126
126
}
0 commit comments