accumulo-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From keith-turner <...@git.apache.org>
Subject [GitHub] accumulo pull request #145: ACCUMULO-4376 add KeyBuilder
Date Fri, 02 Sep 2016 01:21:20 GMT
Github user keith-turner commented on a diff in the pull request:

    https://github.com/apache/accumulo/pull/145#discussion_r77281256
  
    --- Diff: core/src/test/java/org/apache/accumulo/core/data/KeyBuilderTest.java ---
    @@ -0,0 +1,282 @@
    +/*
    + * Licensed to the Apache Software Foundation (ASF) under one or more
    + * contributor license agreements.  See the NOTICE file distributed with
    + * this work for additional information regarding copyright ownership.
    + * The ASF licenses this file to You under the Apache License, Version 2.0
    + * (the "License"); you may not use this file except in compliance with
    + * the License.  You may obtain a copy of the License at
    + *
    + *     http://www.apache.org/licenses/LICENSE-2.0
    + *
    + * Unless required by applicable law or agreed to in writing, software
    + * distributed under the License is distributed on an "AS IS" BASIS,
    + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    + * See the License for the specific language governing permissions and
    + * limitations under the License.
    + */
    +package org.apache.accumulo.core.data;
    +
    +import org.apache.hadoop.io.Text;
    +import org.junit.Test;
    +
    +import static org.junit.Assert.*;
    +
    +public class KeyBuilderTest {
    +
    +  private static final byte EMPTY_BYTES[] = new byte[0];
    +  byte[] rowBytes = "row".getBytes();
    +  byte[] familyBytes = "family".getBytes();
    +  byte[] qualifierBytes = "qualifier".getBytes();
    +  byte[] visibilityBytes = "visibility".getBytes();
    +  Text rowText = new Text(rowBytes);
    +  Text familyText = new Text(familyBytes);
    +  Text qualifierText = new Text(qualifierBytes);
    +  Text visibilityText = new Text(visibilityBytes);
    +
    +  @Test
    +  public void testKeyBuildingFromRow() {
    +    Key keyBuilt  = Key.builder().row("foo").build();
    +    Key keyExpected = new Key("foo");
    +    assertEquals(keyExpected, keyBuilt);
    +  }
    +
    +  @Test
    +  public void testKeyBuildingFromRowFamily() {
    +    Key keyBuilt = Key.builder().row("foo").family("bar").build();
    +    Key keyExpected = new Key("foo", "bar");
    +    assertEquals(keyExpected, keyBuilt);
    +  }
    +
    +  @Test
    +  public void testKeyBuildingFromRowFamilyQualifier() {
    +    Key keyBuilt = Key.builder().row("foo").family("bar").qualifier("baz").build();
    +    Key keyExpected = new Key("foo", "bar", "baz");
    +    assertEquals(keyExpected, keyBuilt);
    +  }
    +
    +  @Test
    +  public void testKeyBuildingFromRowFamilyQualifierVisibility() {
    +    Key keyBuilt = Key.builder().row("foo").family("bar").qualifier("baz").visibility("v").build();
    +    Key keyExpected = new Key("foo", "bar", "baz", "v");
    +    assertEquals(keyExpected, keyBuilt);
    +  }
    +
    +  @Test
    +  public void testKeyBuildingFromRowFamilyQualifierVisibilityTimestamp() {
    +    Key keyBuilt = Key.builder().row("foo").family("bar").qualifier("baz").visibility("v").timestamp(1L).build();
    +    Key keyExpected = new Key("foo", "bar", "baz", "v", 1L);
    +    assertEquals(keyExpected, keyBuilt);
    +  }
    +
    +  @Test
    +  public void testKeyBuildingFromRowFamilyQualifierVisibilityTimestampDeleted() {
    +    Key keyBuilt =
    +        Key.builder()
    +            .row("foo")
    +            .family("bar")
    +            .qualifier("baz")
    +            .visibility("v")
    +            .timestamp(10L)
    +            .deleted(true)
    +            .build();
    +    Key keyExpected = new Key("foo", "bar", "baz", "v", 10L);
    +    keyExpected.setDeleted(true);
    +    assertEquals(keyExpected, keyBuilt);
    +  }
    +
    +  @Test
    +  public void testKeyBuildingFromRowVisibility() {
    +    Key keyBuilt = Key.builder().row("foo").visibility("v").build();
    +    Key keyExpected = new Key("foo", "", "", "v");
    +    assertEquals(keyExpected, keyBuilt);
    +  }
    +
    +  @Test
    +  public void testKeyBuildingFromRowFamilyVisibility() {
    +    Key keyBuilt = Key.builder().row("foo").family("bar").visibility("v").build();
    +    Key keyExpected = new Key("foo", "bar", "", "v");
    +    assertEquals(keyExpected, keyBuilt);
    +  }
    +
    +  @Test
    +  public void textKeyBuildingFromRowTimestamp() {
    +    Key keyBuilt = Key.builder().row("foo").timestamp(3L).build();
    +    Key keyExpected = new Key("foo");
    +    keyExpected.setTimestamp(3L);
    +    assertEquals(keyExpected, keyBuilt);
    +  }
    +
    +  @Test
    +  public void testKeyBuildingFromRowBytes() {
    +    Key keyBuilt  = Key.builder().row(rowBytes).build();
    +    Key keyExpected = new Key(rowBytes, EMPTY_BYTES, EMPTY_BYTES, EMPTY_BYTES, Long.MAX_VALUE);
    +    assertEquals(keyExpected, keyBuilt);
    +  }
    +
    +  @Test
    +  public void testKeyBuildingFromRowFamilyBytes() {
    +    Key keyBuilt = Key.builder().row(rowBytes).family(familyBytes).build();
    +    Key keyExpected = new Key(rowBytes, familyBytes, EMPTY_BYTES, EMPTY_BYTES, Long.MAX_VALUE);
    +    assertEquals(keyExpected, keyBuilt);
    +  }
    +
    +  @Test
    +  public void testKeyBuildingFromRowFamilyQualifierBytes() {
    +    Key keyBuilt = Key.builder().row(rowBytes).family(familyBytes).qualifier(qualifierBytes).build();
    +    Key keyExpected = new Key(rowBytes, familyBytes, qualifierBytes, EMPTY_BYTES, Long.MAX_VALUE);
    +    assertEquals(keyExpected, keyBuilt);
    +  }
    +
    +  @Test
    +  public void testKeyBuildingFromRowFamilyQualifierVisibilityBytes() {
    +    Key keyBuilt  = Key.builder().row(rowBytes).family(familyBytes).qualifier(qualifierBytes).visibility(visibilityBytes).build();
    +    Key keyExpected = new Key(rowBytes, familyBytes, qualifierBytes, visibilityBytes,
Long.MAX_VALUE);
    +    assertEquals(keyExpected, keyBuilt);
    +  }
    +
    +  @Test
    +  public void testKeyBuildingFromRowFamilyQualifierVisibilityTimestampBytes() {
    +    Key keyBuilt = Key.builder().row(rowBytes).family(familyBytes).qualifier(qualifierBytes).visibility(visibilityBytes).timestamp(1L).build();
    +    Key keyExpected = new Key(rowBytes, familyBytes, qualifierBytes, visibilityBytes,
1L);
    +    assertEquals(keyExpected, keyBuilt);
    +  }
    +
    +  @Test
    +  public void testKeyBuildingFromRowFamilyQualifierVisibilityTimestampDeletedBytes()
{
    +    Key keyBuilt =
    +        Key.builder()
    +            .row(rowBytes)
    +            .family(familyBytes)
    +            .qualifier(qualifierBytes)
    +            .visibility(visibilityBytes)
    +            .timestamp(10L)
    +            .deleted(true)
    +            .build();
    +    Key keyExpected = new Key(rowBytes, familyBytes, qualifierBytes, visibilityBytes,
10L);
    +    keyExpected.setDeleted(true);
    +    assertEquals(keyExpected, keyBuilt);
    +  }
    +
    +  @Test
    +  public void testKeyBuildingFromRowVisibilityBytes() {
    +    Key keyBuilt = Key.builder().row(rowBytes).visibility(visibilityBytes).build();
    +    Key keyExpected = new Key(rowBytes, EMPTY_BYTES, EMPTY_BYTES, visibilityBytes, Long.MAX_VALUE);
    +    assertEquals(keyExpected, keyBuilt);
    +  }
    +
    +  @Test
    +  public void testKeyBuildingFromRowFamilyVisibilityBytes() {
    +    Key keyBuilt = Key.builder().row(rowBytes).family(familyBytes).visibility(visibilityBytes).build();
    +    Key keyExpected = new Key(rowBytes, familyBytes, EMPTY_BYTES, visibilityBytes, Long.MAX_VALUE);
    +    assertEquals(keyExpected, keyBuilt);
    +  }
    +
    +  @Test
    +  public void textKeyBuildingFromRowTimestampBytes() {
    +    Key keyBuilt = Key.builder().row(rowBytes).timestamp(3L).build();
    +    Key keyExpected = new Key(rowBytes, EMPTY_BYTES, EMPTY_BYTES, EMPTY_BYTES, Long.MAX_VALUE);
    +    keyExpected.setTimestamp(3L);
    +    assertEquals(keyExpected, keyBuilt);
    +  }
    +
    +  @Test
    +  public void testKeyBuildingFromRowText() {
    +    Key keyBuilt  = Key.builder().row(rowText).build();
    +    Key keyExpected = new Key(rowText);
    +    assertEquals(keyExpected, keyBuilt);
    +  }
    +
    +  @Test
    +  public void testKeyBuildingFromRowFamilyText() {
    +    Key keyBuilt = Key.builder().row(rowText).family(familyText).build();
    +    Key keyExpected = new Key(rowText, familyText);
    +    assertEquals(keyExpected, keyBuilt);
    +  }
    +
    +  @Test
    +  public void testKeyBuildingFromRowFamilyQualifierText() {
    +    Key keyBuilt = Key.builder().row(rowText).family(familyText).qualifier(qualifierText).build();
    +    Key keyExpected = new Key(rowText, familyText, qualifierText);
    +    assertEquals(keyExpected, keyBuilt);
    +  }
    +
    +  @Test
    +  public void testKeyBuildingFromRowFamilyQualifierVisibilityText() {
    +    Key keyBuilt  = Key.builder().row(rowText).family(familyText).qualifier(qualifierText).visibility(visibilityText).build();
    +    Key keyExpected = new Key(rowText, familyText, qualifierText, visibilityText);
    +    assertEquals(keyExpected, keyBuilt);
    +  }
    +
    +  @Test
    +  public void testKeyBuildingFromRowFamilyQualifierVisibilityTimestampText() {
    +    Key keyBuilt = Key.builder().row(rowText).family(familyText).qualifier(qualifierText).visibility(visibilityText).timestamp(1L).build();
    +    Key keyExpected = new Key(rowText, familyText, qualifierText, visibilityText, 1L);
    +    assertEquals(keyExpected, keyBuilt);
    +  }
    +
    +  @Test
    +  public void testKeyBuildingFromRowFamilyQualifierVisibilityTimestampDeletedText() {
    +    Key keyBuilt =
    +        Key.builder()
    +            .row(rowText)
    +            .family(familyText)
    +            .qualifier(qualifierText)
    +            .visibility(visibilityText)
    +            .timestamp(10L)
    +            .deleted(true)
    +            .build();
    +    Key keyExpected = new Key(rowText, familyText, qualifierText, visibilityText, 10L);
    +    keyExpected.setDeleted(true);
    +    assertEquals(keyExpected, keyBuilt);
    +  }
    +
    +  @Test
    +  public void testKeyBuildingFromRowVisibilityText() {
    +    Key keyBuilt = Key.builder().row(rowText).visibility(visibilityText).build();
    +    Key keyExpected = new Key(rowText, new Text(), new Text(), visibilityText);
    +    assertEquals(keyExpected, keyBuilt);
    +  }
    +
    +  @Test
    +  public void testKeyBuildingFromRowFamilyVisibilityText() {
    +    Key keyBuilt = Key.builder().row(rowText).family(familyText).visibility(visibilityText).build();
    +    Key keyExpected = new Key(rowText, familyText, new Text(), visibilityText);
    +    assertEquals(keyExpected, keyBuilt);
    +  }
    +
    +  @Test
    +  public void testKeyBuildingFromRowTimestampText() {
    +    Key keyBuilt = Key.builder().row(rowText).timestamp(3L).build();
    +    Key keyExpected = new Key(rowText);
    +    keyExpected.setTimestamp(3L);
    +    assertEquals(keyExpected, keyBuilt);
    +  }
    +
    +  @Test
    +  public void testKeyBuildingReusingBytes() {
    +    byte[] reuse = new byte[] { 1, 2, 3 };
    +    KeyBuilder.Build keyBuilder = Key.builder(false).row(reuse);
    +    Key keyBuilt = keyBuilder.build();
    +    assertEquals(reuse, keyBuilt.getRowBytes());
    --- End diff --
    
    Could use `assertSame()` here.  Its not needed for correctness in this case, just makes
intentions clear.   


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

Mime
View raw message