-
Notifications
You must be signed in to change notification settings - Fork 2.2k
[Event Hubs] Replace constant strings with resource strings #3923 #6529
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
102b8ff
[Event Hubs] Replace constant strings with resource strings #3923
acd3d98
Switch to JUnit version 5 for unit tests #4955
7ec47c6
[Event Hubs] Replace constant strings with resource strings #3923
4939b1f
Merge branch 'master' into issues/3923_messaging_eventhubs
222c08f
[Event Hubs] Replace constant strings with resource strings #3923
dfd54cd
[Event Hubs] Replace constant strings with resource strings #3923
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
...thubs/azure-messaging-eventhubs/src/main/java/com/azure/messaging/eventhubs/Messages.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| // Licensed under the MIT License. | ||
|
|
||
| package com.azure.messaging.eventhubs; | ||
|
|
||
| import com.azure.core.util.logging.ClientLogger; | ||
|
|
||
| import java.io.IOException; | ||
| import java.io.InputStream; | ||
| import java.util.Properties; | ||
|
|
||
| /** | ||
| * I18n messages loaded from the messages.properties file located within the same package. | ||
| */ | ||
| public enum Messages { | ||
| ; | ||
| private static final ClientLogger LOGGER = new ClientLogger(Messages.class); | ||
mclay marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| private static Properties properties; | ||
| private static final String MESSAGES_PROPERTIES_PATH = "com/azure/messaging/eventhubs/messages.properties"; | ||
| public static final String CLASS_NOT_A_SUPPORTED_TYPE = getMessage("CLASS_NOT_A_SUPPORTED_TYPE"); | ||
| public static final String ENCODING_TYPE_NOT_SUPPORTED = getMessage("ENCODING_TYPE_NOT_SUPPORTED"); | ||
| public static final String PROCESS_SPAN_SCOPE_TYPE_ERROR = getMessage("PROCESS_SPAN_SCOPE_TYPE_ERROR"); | ||
| public static final String MESSAGE_NOT_OF_TYPE = getMessage("MESSAGE_NOT_OF_TYPE"); | ||
| public static final String REQUEST_VALUE_NOT_VALID = getMessage("REQUEST_VALUE_NOT_VALID"); | ||
| public static final String EVENT_DATA_DOES_NOT_FIT = getMessage("EVENT_DATA_DOES_NOT_FIT"); | ||
| public static final String CANNOT_SEND_EVENT_BATCH_EMPTY = getMessage("CANNOT_SEND_EVENT_BATCH_EMPTY"); | ||
| public static final String ERROR_SENDING_BATCH = getMessage("ERROR_SENDING_BATCH"); | ||
| public static final String FAILED_TO_CLAIM_OWNERSHIP = getMessage("FAILED_TO_CLAIM_OWNERSHIP"); | ||
| public static final String LOAD_BALANCING_FAILED = getMessage("LOAD_BALANCING_FAILED"); | ||
| public static final String EVENT_PROCESSOR_RUN_END = getMessage("EVENT_PROCESSOR_RUN_END"); | ||
| public static final String FAILED_PROCESSING_ERROR_RECEIVE = getMessage("FAILED_PROCESSING_ERROR_RECEIVE"); | ||
| public static final String FAILED_WHILE_PROCESSING_ERROR = getMessage("FAILED_WHILE_PROCESSING_ERROR"); | ||
| public static final String FAILED_CLOSE_CONSUMER_PARTITION = getMessage("FAILED_CLOSE_CONSUMER_PARTITION"); | ||
| public static final String ERROR_OCCURRED_IN_SUBSCRIBER_ERROR = getMessage("ERROR_OCCURRED_IN_SUBSCRIBER_ERROR"); | ||
| public static final String EXCEPTION_OCCURRED_WHILE_EMITTING = getMessage("EXCEPTION_OCCURRED_WHILE_EMITTING"); | ||
|
|
||
| private static synchronized Properties getProperties() { | ||
| if (properties != null) { | ||
| return properties; | ||
| } | ||
| properties = new Properties(); | ||
| try (InputStream inputStream = | ||
| Thread.currentThread().getContextClassLoader().getResourceAsStream(MESSAGES_PROPERTIES_PATH)) { | ||
| if (inputStream != null) { | ||
| properties.load(inputStream); | ||
| } else { | ||
| LOGGER.error("Message properties [{}] not found", MESSAGES_PROPERTIES_PATH); //NON-NLS | ||
| } | ||
| } catch (IOException exception) { | ||
| LOGGER.error("Error loading message properties [{}]", MESSAGES_PROPERTIES_PATH, exception); //NON-NLS | ||
| } | ||
| return properties; | ||
| } | ||
|
|
||
| /** | ||
| * @param key the key of the message to retrieve | ||
| * @return the message matching the given key | ||
| */ | ||
| public static String getMessage(String key) { | ||
| return String.valueOf(getProperties().getOrDefault(key, key)); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
...-messaging-eventhubs/src/main/resources/com/azure/messaging/eventhubs/messages.properties
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| PROCESS_SPAN_SCOPE_TYPE_ERROR=Process span scope type is not of type Closeable, but type: %s. Not closing the scope and span | ||
| MESSAGE_NOT_OF_TYPE=Message body type is not of type Data, but type: %s. Not setting body contents. | ||
| REQUEST_VALUE_NOT_VALID=Back pressure request value not valid. It must be between {} and {}. | ||
| EVENT_DATA_DOES_NOT_FIT=EventData does not fit into maximum number of batches. '%s' | ||
| CANNOT_SEND_EVENT_BATCH_EMPTY=Cannot send an EventBatch that is empty. | ||
| ERROR_SENDING_BATCH=Error sending batch. | ||
| FAILED_TO_CLAIM_OWNERSHIP=Failed to claim ownership of partition {} - {} | ||
| LOAD_BALANCING_FAILED=Load balancing for event processor failed - {} | ||
| EVENT_PROCESSOR_RUN_END=EventProcessor.run() endTracingSpan().close() failed with an error %s | ||
| FAILED_PROCESSING_ERROR_RECEIVE=Failed while processing error on receive {} | ||
| FAILED_WHILE_PROCESSING_ERROR=Failed while processing error {} | ||
| FAILED_CLOSE_CONSUMER_PARTITION=Failed to close consumer for partition {} | ||
| ERROR_OCCURRED_IN_SUBSCRIBER_ERROR=Error occurred in subscriber. Error: {} | ||
| EXCEPTION_OCCURRED_WHILE_EMITTING=Exception occurred while emitting next received event. | ||
| CLASS_NOT_A_SUPPORTED_TYPE=Class '%s' is not a supported deserializable type. | ||
| ENCODING_TYPE_NOT_SUPPORTED=Encoding Type: %s is not supported |
35 changes: 35 additions & 0 deletions
35
...s/azure-messaging-eventhubs/src/test/java/com/azure/messaging/eventhubs/MessagesTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| // Licensed under the MIT License. | ||
|
|
||
| package com.azure.messaging.eventhubs; | ||
|
|
||
| import org.junit.jupiter.params.ParameterizedTest; | ||
| import org.junit.jupiter.params.provider.MethodSource; | ||
|
|
||
| import java.lang.reflect.Field; | ||
| import java.util.Objects; | ||
| import java.util.stream.Stream; | ||
|
|
||
| import static org.junit.jupiter.api.Assertions.assertEquals; | ||
| import static org.junit.jupiter.api.Assertions.assertNotEquals; | ||
|
|
||
| class MessagesTest { | ||
|
|
||
| static Stream<String> keys() { | ||
| return Stream.of(Messages.class.getFields()).map(Field::getName); | ||
| } | ||
|
|
||
| @ParameterizedTest | ||
| @MethodSource("keys") | ||
| void getMessage(String messageKey) { | ||
| assertNotEquals(messageKey, Messages.getMessage(messageKey)); | ||
| } | ||
|
|
||
| @ParameterizedTest | ||
| @MethodSource("keys") | ||
| void messageField(String messageKey) throws NoSuchFieldException, IllegalAccessException { | ||
| Field field = Messages.class.getField(messageKey); | ||
| field.setAccessible(true); | ||
| assertEquals(Messages.getMessage(messageKey), Objects.toString(field.get(Messages.class))); | ||
| } | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.