|
26 | 26 | import static org.apache.hadoop.hbase.quotas.ThrottleQuotaTestUtil.triggerUserCacheRefresh; |
27 | 27 | import static org.apache.hadoop.hbase.quotas.ThrottleQuotaTestUtil.waitMinuteQuota; |
28 | 28 | import static org.junit.Assert.assertEquals; |
| 29 | +import static org.junit.Assert.assertTrue; |
29 | 30 |
|
| 31 | +import java.io.IOException; |
| 32 | +import java.util.List; |
30 | 33 | import java.util.concurrent.TimeUnit; |
31 | 34 | import org.apache.hadoop.hbase.HBaseClassTestRule; |
32 | 35 | import org.apache.hadoop.hbase.HBaseTestingUtil; |
@@ -652,4 +655,39 @@ public void testExceedThrottleQuota() throws Exception { |
652 | 655 | admin.setQuota(QuotaSettingsFactory.unthrottleTable(TABLE_NAMES[0])); |
653 | 656 | triggerTableCacheRefresh(TEST_UTIL, true, TABLE_NAMES[0]); |
654 | 657 | } |
| 658 | + |
| 659 | + @Test |
| 660 | + public void testSetAndGetAllThrottleTypes() throws Exception { |
| 661 | + for (ThrottleType throttleType : ThrottleType.values()) { |
| 662 | + canSetAndGetUserThrottle(throttleType); |
| 663 | + } |
| 664 | + } |
| 665 | + |
| 666 | + private void canSetAndGetUserThrottle(ThrottleType throttleType) throws IOException { |
| 667 | + final Admin admin = TEST_UTIL.getAdmin(); |
| 668 | + final String userName = User.getCurrent().getShortName(); |
| 669 | + |
| 670 | + QuotaSettings setQuota = |
| 671 | + QuotaSettingsFactory.throttleUser(userName, throttleType, 123, TimeUnit.SECONDS); |
| 672 | + admin.setQuota(setQuota); |
| 673 | + |
| 674 | + boolean found = false; |
| 675 | + List<QuotaSettings> quotaSettings = admin.getQuota(new QuotaFilter().setUserFilter(userName)); |
| 676 | + for (QuotaSettings settings : quotaSettings) { |
| 677 | + if (settings instanceof ThrottleSettings) { |
| 678 | + ThrottleSettings throttle = (ThrottleSettings) settings; |
| 679 | + if ( |
| 680 | + userName.equals(throttle.getUserName()) && throttle.getThrottleType() == throttleType |
| 681 | + && throttle.getSoftLimit() == 123 && throttle.getTimeUnit() == TimeUnit.SECONDS |
| 682 | + ) { |
| 683 | + found = true; |
| 684 | + break; |
| 685 | + } |
| 686 | + } |
| 687 | + } |
| 688 | + |
| 689 | + assertTrue("Expected to find " + throttleType.name() + " quota for user " + userName, found); |
| 690 | + admin.setQuota(QuotaSettingsFactory.unthrottleUserByThrottleType(userName, throttleType)); |
| 691 | + } |
| 692 | + |
655 | 693 | } |
0 commit comments