Search in sources :

Example 1 with Size

use of org.apache.hadoop.hbase.Size in project hbase by apache.

the class TestFieldValue method testParseAndAsSomethingMethod.

@Test
public void testParseAndAsSomethingMethod() {
    // String
    FieldValue stringFieldValue = new FieldValue("aaa", FieldValueType.STRING);
    assertThat(stringFieldValue.asString(), is("aaa"));
    try {
        new FieldValue(1, FieldValueType.STRING);
        fail();
    } catch (IllegalArgumentException ignored) {
    }
    // Integer
    FieldValue integerFieldValue = new FieldValue(100, FieldValueType.INTEGER);
    assertThat(integerFieldValue.asInt(), is(100));
    integerFieldValue = new FieldValue("100", FieldValueType.INTEGER);
    assertThat(integerFieldValue.asInt(), is(100));
    try {
        new FieldValue("aaa", FieldValueType.INTEGER);
        fail();
    } catch (IllegalArgumentException ignored) {
    }
    // Long
    FieldValue longFieldValue = new FieldValue(100L, FieldValueType.LONG);
    assertThat(longFieldValue.asLong(), is(100L));
    longFieldValue = new FieldValue("100", FieldValueType.LONG);
    assertThat(longFieldValue.asLong(), is(100L));
    try {
        new FieldValue("aaa", FieldValueType.LONG);
        fail();
    } catch (IllegalArgumentException ignored) {
    }
    try {
        new FieldValue(100, FieldValueType.LONG);
        fail();
    } catch (IllegalArgumentException ignored) {
    }
    // Float
    FieldValue floatFieldValue = new FieldValue(1.0f, FieldValueType.FLOAT);
    assertThat(floatFieldValue.asFloat(), is(1.0f));
    floatFieldValue = new FieldValue("1", FieldValueType.FLOAT);
    assertThat(floatFieldValue.asFloat(), is(1.0f));
    try {
        new FieldValue("aaa", FieldValueType.FLOAT);
        fail();
    } catch (IllegalArgumentException ignored) {
    }
    try {
        new FieldValue(1, FieldValueType.FLOAT);
        fail();
    } catch (IllegalArgumentException ignored) {
    }
    // Size
    FieldValue sizeFieldValue = new FieldValue(new Size(100, Size.Unit.MEGABYTE), FieldValueType.SIZE);
    assertThat(sizeFieldValue.asString(), is("100.0MB"));
    assertThat(sizeFieldValue.asSize(), is(new Size(100, Size.Unit.MEGABYTE)));
    sizeFieldValue = new FieldValue("100MB", FieldValueType.SIZE);
    assertThat(sizeFieldValue.asString(), is("100.0MB"));
    assertThat(sizeFieldValue.asSize(), is(new Size(100, Size.Unit.MEGABYTE)));
    try {
        new FieldValue("100", FieldValueType.SIZE);
        fail();
    } catch (IllegalArgumentException ignored) {
    }
    try {
        new FieldValue(100, FieldValueType.SIZE);
        fail();
    } catch (IllegalArgumentException ignored) {
    }
    // Percent
    FieldValue percentFieldValue = new FieldValue(100f, FieldValueType.PERCENT);
    assertThat(percentFieldValue.asString(), is("100.00%"));
    assertThat(percentFieldValue.asFloat(), is(100f));
    percentFieldValue = new FieldValue("100%", FieldValueType.PERCENT);
    assertThat(percentFieldValue.asString(), is("100.00%"));
    assertThat(percentFieldValue.asFloat(), is(100f));
    percentFieldValue = new FieldValue("100", FieldValueType.PERCENT);
    assertThat(percentFieldValue.asString(), is("100.00%"));
    assertThat(percentFieldValue.asFloat(), is(100f));
    try {
        new FieldValue(100, FieldValueType.PERCENT);
        fail();
    } catch (IllegalArgumentException ignored) {
    }
}
Also used : Size(org.apache.hadoop.hbase.Size) Test(org.junit.Test)

Example 2 with Size

use of org.apache.hadoop.hbase.Size in project hbase by apache.

the class TestFieldValue method testCompareTo.

@Test
public void testCompareTo() {
    // String
    FieldValue stringAFieldValue = new FieldValue("a", FieldValueType.STRING);
    FieldValue stringAFieldValue2 = new FieldValue("a", FieldValueType.STRING);
    FieldValue stringBFieldValue = new FieldValue("b", FieldValueType.STRING);
    FieldValue stringCapitalAFieldValue = new FieldValue("A", FieldValueType.STRING);
    assertThat(stringAFieldValue.compareTo(stringAFieldValue2), is(0));
    assertThat(stringBFieldValue.compareTo(stringAFieldValue), is(1));
    assertThat(stringAFieldValue.compareTo(stringBFieldValue), is(-1));
    assertThat(stringAFieldValue.compareTo(stringCapitalAFieldValue), is(32));
    // Integer
    FieldValue integer1FieldValue = new FieldValue(1, FieldValueType.INTEGER);
    FieldValue integer1FieldValue2 = new FieldValue(1, FieldValueType.INTEGER);
    FieldValue integer2FieldValue = new FieldValue(2, FieldValueType.INTEGER);
    assertThat(integer1FieldValue.compareTo(integer1FieldValue2), is(0));
    assertThat(integer2FieldValue.compareTo(integer1FieldValue), is(1));
    assertThat(integer1FieldValue.compareTo(integer2FieldValue), is(-1));
    // Long
    FieldValue long1FieldValue = new FieldValue(1L, FieldValueType.LONG);
    FieldValue long1FieldValue2 = new FieldValue(1L, FieldValueType.LONG);
    FieldValue long2FieldValue = new FieldValue(2L, FieldValueType.LONG);
    assertThat(long1FieldValue.compareTo(long1FieldValue2), is(0));
    assertThat(long2FieldValue.compareTo(long1FieldValue), is(1));
    assertThat(long1FieldValue.compareTo(long2FieldValue), is(-1));
    // Float
    FieldValue float1FieldValue = new FieldValue(1.0f, FieldValueType.FLOAT);
    FieldValue float1FieldValue2 = new FieldValue(1.0f, FieldValueType.FLOAT);
    FieldValue float2FieldValue = new FieldValue(2.0f, FieldValueType.FLOAT);
    assertThat(float1FieldValue.compareTo(float1FieldValue2), is(0));
    assertThat(float2FieldValue.compareTo(float1FieldValue), is(1));
    assertThat(float1FieldValue.compareTo(float2FieldValue), is(-1));
    // Size
    FieldValue size100MBFieldValue = new FieldValue(new Size(100, Size.Unit.MEGABYTE), FieldValueType.SIZE);
    FieldValue size100MBFieldValue2 = new FieldValue(new Size(100, Size.Unit.MEGABYTE), FieldValueType.SIZE);
    FieldValue size200MBFieldValue = new FieldValue(new Size(200, Size.Unit.MEGABYTE), FieldValueType.SIZE);
    assertThat(size100MBFieldValue.compareTo(size100MBFieldValue2), is(0));
    assertThat(size200MBFieldValue.compareTo(size100MBFieldValue), is(1));
    assertThat(size100MBFieldValue.compareTo(size200MBFieldValue), is(-1));
    // Percent
    FieldValue percent50FieldValue = new FieldValue(50.0f, FieldValueType.PERCENT);
    FieldValue percent50FieldValue2 = new FieldValue(50.0f, FieldValueType.PERCENT);
    FieldValue percent100FieldValue = new FieldValue(100.0f, FieldValueType.PERCENT);
    assertThat(percent50FieldValue.compareTo(percent50FieldValue2), is(0));
    assertThat(percent100FieldValue.compareTo(percent50FieldValue), is(1));
    assertThat(percent50FieldValue.compareTo(percent100FieldValue), is(-1));
}
Also used : Size(org.apache.hadoop.hbase.Size) Test(org.junit.Test)

Example 3 with Size

use of org.apache.hadoop.hbase.Size in project hbase by apache.

the class TestFieldValue method testOptimizeSize.

@Test
public void testOptimizeSize() {
    FieldValue sizeFieldValue = new FieldValue(new Size(1, Size.Unit.BYTE), FieldValueType.SIZE);
    assertThat(sizeFieldValue.asString(), is("1.0B"));
    sizeFieldValue = new FieldValue(new Size(1024, Size.Unit.BYTE), FieldValueType.SIZE);
    assertThat(sizeFieldValue.asString(), is("1.0KB"));
    sizeFieldValue = new FieldValue(new Size(2 * 1024, Size.Unit.BYTE), FieldValueType.SIZE);
    assertThat(sizeFieldValue.asString(), is("2.0KB"));
    sizeFieldValue = new FieldValue(new Size(2 * 1024, Size.Unit.KILOBYTE), FieldValueType.SIZE);
    assertThat(sizeFieldValue.asString(), is("2.0MB"));
    sizeFieldValue = new FieldValue(new Size(1024 * 1024, Size.Unit.KILOBYTE), FieldValueType.SIZE);
    assertThat(sizeFieldValue.asString(), is("1.0GB"));
    sizeFieldValue = new FieldValue(new Size(2 * 1024 * 1024, Size.Unit.MEGABYTE), FieldValueType.SIZE);
    assertThat(sizeFieldValue.asString(), is("2.0TB"));
    sizeFieldValue = new FieldValue(new Size(2 * 1024, Size.Unit.TERABYTE), FieldValueType.SIZE);
    assertThat(sizeFieldValue.asString(), is("2.0PB"));
    sizeFieldValue = new FieldValue(new Size(1024 * 1024, Size.Unit.TERABYTE), FieldValueType.SIZE);
    assertThat(sizeFieldValue.asString(), is("1024.0PB"));
    sizeFieldValue = new FieldValue(new Size(1, Size.Unit.PETABYTE), FieldValueType.SIZE);
    assertThat(sizeFieldValue.asString(), is("1.0PB"));
    sizeFieldValue = new FieldValue(new Size(1024, Size.Unit.PETABYTE), FieldValueType.SIZE);
    assertThat(sizeFieldValue.asString(), is("1024.0PB"));
}
Also used : Size(org.apache.hadoop.hbase.Size) Test(org.junit.Test)

Example 4 with Size

use of org.apache.hadoop.hbase.Size in project hbase by apache.

the class TestFieldValue method testPlus.

@Test
public void testPlus() {
    // String
    FieldValue stringFieldValue = new FieldValue("a", FieldValueType.STRING);
    FieldValue stringFieldValue2 = new FieldValue("b", FieldValueType.STRING);
    assertThat(stringFieldValue.plus(stringFieldValue2).asString(), is("ab"));
    // Integer
    FieldValue integerFieldValue = new FieldValue(1, FieldValueType.INTEGER);
    FieldValue integerFieldValue2 = new FieldValue(2, FieldValueType.INTEGER);
    assertThat(integerFieldValue.plus(integerFieldValue2).asInt(), is(3));
    // Long
    FieldValue longFieldValue = new FieldValue(1L, FieldValueType.LONG);
    FieldValue longFieldValue2 = new FieldValue(2L, FieldValueType.LONG);
    assertThat(longFieldValue.plus(longFieldValue2).asLong(), is(3L));
    // Float
    FieldValue floatFieldValue = new FieldValue(1.2f, FieldValueType.FLOAT);
    FieldValue floatFieldValue2 = new FieldValue(2.2f, FieldValueType.FLOAT);
    assertThat(floatFieldValue.plus(floatFieldValue2).asFloat(), is(3.4f));
    // Size
    FieldValue sizeFieldValue = new FieldValue(new Size(100, Size.Unit.MEGABYTE), FieldValueType.SIZE);
    FieldValue sizeFieldValue2 = new FieldValue(new Size(200, Size.Unit.MEGABYTE), FieldValueType.SIZE);
    assertThat(sizeFieldValue.plus(sizeFieldValue2).asString(), is("300.0MB"));
    assertThat(sizeFieldValue.plus(sizeFieldValue2).asSize(), is(new Size(300, Size.Unit.MEGABYTE)));
    // Percent
    FieldValue percentFieldValue = new FieldValue(30f, FieldValueType.PERCENT);
    FieldValue percentFieldValue2 = new FieldValue(60f, FieldValueType.PERCENT);
    assertThat(percentFieldValue.plus(percentFieldValue2).asString(), is("90.00%"));
    assertThat(percentFieldValue.plus(percentFieldValue2).asFloat(), is(90f));
}
Also used : Size(org.apache.hadoop.hbase.Size) Test(org.junit.Test)

Example 5 with Size

use of org.apache.hadoop.hbase.Size in project hbase by apache.

the class TestStochasticLoadBalancer method testKeepRegionLoad.

@Test
public void testKeepRegionLoad() throws Exception {
    ServerName sn = ServerName.valueOf("test:8080", 100);
    int numClusterStatusToAdd = 20000;
    for (int i = 0; i < numClusterStatusToAdd; i++) {
        ServerMetrics sl = mock(ServerMetrics.class);
        RegionMetrics rl = mock(RegionMetrics.class);
        when(rl.getReadRequestCount()).thenReturn(0L);
        when(rl.getCpRequestCount()).thenReturn(0L);
        when(rl.getWriteRequestCount()).thenReturn(0L);
        when(rl.getMemStoreSize()).thenReturn(Size.ZERO);
        when(rl.getStoreFileSize()).thenReturn(new Size(i, Size.Unit.MEGABYTE));
        Map<byte[], RegionMetrics> regionLoadMap = new TreeMap<>(Bytes.BYTES_COMPARATOR);
        regionLoadMap.put(Bytes.toBytes(REGION_KEY), rl);
        when(sl.getRegionMetrics()).thenReturn(regionLoadMap);
        ClusterMetrics clusterStatus = mock(ClusterMetrics.class);
        Map<ServerName, ServerMetrics> serverMetricsMap = new TreeMap<>();
        serverMetricsMap.put(sn, sl);
        when(clusterStatus.getLiveServerMetrics()).thenReturn(serverMetricsMap);
        loadBalancer.updateClusterMetrics(clusterStatus);
    }
    String regionNameAsString = RegionInfo.getRegionNameAsString(Bytes.toBytes(REGION_KEY));
    assertTrue(loadBalancer.loads.get(regionNameAsString) != null);
    assertTrue(loadBalancer.loads.get(regionNameAsString).size() == 15);
    Queue<BalancerRegionLoad> loads = loadBalancer.loads.get(regionNameAsString);
    int i = 0;
    while (loads.size() > 0) {
        BalancerRegionLoad rl = loads.remove();
        assertEquals(i + (numClusterStatusToAdd - 15), rl.getStorefileSizeMB());
        i++;
    }
}
Also used : ClusterMetrics(org.apache.hadoop.hbase.ClusterMetrics) Size(org.apache.hadoop.hbase.Size) ServerName(org.apache.hadoop.hbase.ServerName) ServerMetrics(org.apache.hadoop.hbase.ServerMetrics) TreeMap(java.util.TreeMap) RegionMetrics(org.apache.hadoop.hbase.RegionMetrics) Test(org.junit.Test)

Aggregations

Size (org.apache.hadoop.hbase.Size)11 Test (org.junit.Test)7 RegionMetrics (org.apache.hadoop.hbase.RegionMetrics)6 ServerName (org.apache.hadoop.hbase.ServerName)5 ArrayList (java.util.ArrayList)3 RegionInfo (org.apache.hadoop.hbase.client.RegionInfo)3 TableDescriptor (org.apache.hadoop.hbase.client.TableDescriptor)3 MasterServices (org.apache.hadoop.hbase.master.MasterServices)3 IOException (java.io.IOException)2 Collections (java.util.Collections)2 Comparator (java.util.Comparator)2 List (java.util.List)2 TimeUnit (java.util.concurrent.TimeUnit)2 HBaseClassTestRule (org.apache.hadoop.hbase.HBaseClassTestRule)2 HBaseTestingUtil (org.apache.hadoop.hbase.HBaseTestingUtil)2 HConstants (org.apache.hadoop.hbase.HConstants)2 MatcherPredicate (org.apache.hadoop.hbase.MatcherPredicate)2 NamespaceDescriptor (org.apache.hadoop.hbase.NamespaceDescriptor)2 TableName (org.apache.hadoop.hbase.TableName)2 ExplainingPredicate (org.apache.hadoop.hbase.Waiter.ExplainingPredicate)2