-
Notifications
You must be signed in to change notification settings - Fork 76
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
88 additions
and
24 deletions.
There are no files selected for viewing
This file contains 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 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 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
18 changes: 18 additions & 0 deletions
18
.../main/java/com/hotels/bdp/waggledance/extensions/client/ratelimit/BucketKeyGenerator.java
This file contains 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,18 @@ | ||
package com.hotels.bdp.waggledance.extensions.client.ratelimit; | ||
|
||
public class BucketKeyGenerator { | ||
|
||
private final String prefix; | ||
|
||
public BucketKeyGenerator(String prefix) { | ||
this.prefix = prefix; | ||
} | ||
|
||
public String generateKey(String key) { | ||
if (prefix != null && !prefix.isEmpty()) { | ||
return prefix + "_" + key; | ||
} | ||
return key; | ||
} | ||
|
||
} |
This file contains 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 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
31 changes: 31 additions & 0 deletions
31
...t/java/com/hotels/bdp/waggledance/extensions/client/ratelimit/BucketKeyGeneratorTest.java
This file contains 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,31 @@ | ||
package com.hotels.bdp.waggledance.extensions.client.ratelimit; | ||
|
||
import static org.hamcrest.CoreMatchers.is; | ||
import static org.hamcrest.MatcherAssert.assertThat; | ||
|
||
import org.junit.Test; | ||
|
||
public class BucketKeyGeneratorTest { | ||
|
||
@Test | ||
public void testGenerateKey() { | ||
BucketKeyGenerator bucketKeyGenerator = new BucketKeyGenerator("prefix"); | ||
String key = bucketKeyGenerator.generateKey("key"); | ||
assertThat(key, is("prefix_key")); | ||
} | ||
|
||
@Test | ||
public void testGenerateKeyNullPrefix() { | ||
BucketKeyGenerator bucketKeyGenerator = new BucketKeyGenerator(null); | ||
String key = bucketKeyGenerator.generateKey("key"); | ||
assertThat(key, is("key")); | ||
} | ||
|
||
@Test | ||
public void testGenerateKeyEmptyPrefix() { | ||
BucketKeyGenerator bucketKeyGenerator = new BucketKeyGenerator(""); | ||
String key = bucketKeyGenerator.generateKey("key"); | ||
assertThat(key, is("key")); | ||
} | ||
|
||
} |
This file contains 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