Commit 7597f4fa authored by Alok Joshi's avatar Alok Joshi
Browse files

Merge branch 'fetch_only_relevant_egrid' into 'master'

Fetch only the required event grid topic details

See merge request !109
parents 127b29ff e644c039
Pipeline #44822 passed with stages
in 6 minutes and 13 seconds
......@@ -71,7 +71,7 @@ public class PartitionServiceEventGridClient {
Validators.checkNotNullAndNotEmpty(partitionId, "partitionId");
Validators.checkNotNullAndNotEmpty(topicName, "topicName");
Map<String, EventGridTopicPartitionInfoAzure> eventGridTopicPartitionInfoAzure = getAllEventGridTopicsInPartition(partitionId);
Map<String, EventGridTopicPartitionInfoAzure> eventGridTopicPartitionInfoAzure = getAllRelevantEventGridTopicsInPartition(partitionId, topicName);
if (!eventGridTopicPartitionInfoAzure.containsKey(topicName)) {
throw new AppException(HttpStatus.SC_INTERNAL_SERVER_ERROR, "Invalid EventGrid Partition configuration for the partition " + partitionId, "Please refer to wiki here <>");
......@@ -80,20 +80,21 @@ public class PartitionServiceEventGridClient {
}
/**
* Get partition info.
* Get relevant event grid topics.
*
* @param partitionId Partition Id
* @return Partition info
* @param topicName Topic Name
* @return Event Grid Topics
* @throws AppException Exception thrown by {@link IPartitionFactory}
* @throws PartitionException Exception thrown by {@link IPartitionFactory}
*/
Map<String, EventGridTopicPartitionInfoAzure> getAllEventGridTopicsInPartition(final String partitionId) throws AppException, PartitionException {
Map<String, EventGridTopicPartitionInfoAzure> getAllRelevantEventGridTopicsInPartition(final String partitionId, final String topicName) throws AppException, PartitionException {
PartitionInfo partitionInfo = getPartitionInfo(partitionId);
Map<String, Property> propertyMap = partitionInfo.getProperties();
Map<String, EventGridTopicPartitionInfoAzure> topics = new HashMap<>();
for (Map.Entry<String, Property> property : propertyMap.entrySet()) {
if (isEventGridProperty(property)) {
if (isEventGridProperty(property) && property.getKey().contains(topicName)) {
StringTokenizer stringTokenizer = new StringTokenizer(property.getKey(), "-");
if (stringTokenizer.countTokens() == 2) {
addEventGridTopicName(topics, property, stringTokenizer);
......
......@@ -66,7 +66,6 @@ public class PartitionServiceEventGridClientTest {
final String eventGridTopicName2 = "testEventGridTopicName2";
final String eventGridTopicAccessKey2 = "testEventGridTopicAccessKey2";
final String topicId1 = "recordstopic";
final String topicId2 = "testtopic";
Map<String, Property> properties = new HashMap<>();
properties.put("id", Property.builder().value(PARTITION_ID).build());
......@@ -85,18 +84,15 @@ public class PartitionServiceEventGridClientTest {
// Act
Map<String, EventGridTopicPartitionInfoAzure> eventGridTopicPartitionInfoAzureMap =
partitionServiceClientSpy.getAllEventGridTopicsInPartition("tenant1");
partitionServiceClientSpy.getAllRelevantEventGridTopicsInPartition("tenant1", "recordstopic");
// Assert
assertEquals(eventGridTopicPartitionInfoAzureMap.size(), 2);
assertEquals(eventGridTopicPartitionInfoAzureMap.size(), 1);
assertTrue(eventGridTopicPartitionInfoAzureMap.containsKey(topicId1));
assertTrue(eventGridTopicPartitionInfoAzureMap.containsKey(topicId2));
// Validate that the EventGridTopicPartitionInfo is mapped correctly.
assertEquals(eventGridTopicPartitionInfoAzureMap.get(topicId1).getTopicName(), eventGridTopicName1);
assertEquals(eventGridTopicPartitionInfoAzureMap.get(topicId1).getTopicAccessKey(), eventGridTopicAccessKey1);
assertEquals(eventGridTopicPartitionInfoAzureMap.get(topicId2).getTopicName(), eventGridTopicName2);
assertEquals(eventGridTopicPartitionInfoAzureMap.get(topicId2).getTopicAccessKey(), eventGridTopicAccessKey2);
}
@Test
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment