nickwallen commented on a change in pull request #1458: METRON-2177 Upgrade 
Profiler for HBase 2.0.2
URL: https://github.com/apache/metron/pull/1458#discussion_r306318215
 
 

 ##########
 File path: 
metron-analytics/metron-profiler-client/src/test/java/org/apache/metron/profiler/client/HBaseProfilerClientTest.java
 ##########
 @@ -20,184 +20,187 @@
 
 package org.apache.metron.profiler.client;
 
-import org.apache.metron.hbase.mock.MockHTable;
+import org.apache.hadoop.hbase.client.Result;
+import org.apache.hadoop.hbase.util.Bytes;
+import org.apache.metron.common.utils.SerDeUtils;
+import org.apache.metron.hbase.client.HBaseTableClient;
+import org.apache.metron.hbase.client.HBaseClient;
 import org.apache.metron.profiler.ProfileMeasurement;
+import org.apache.metron.profiler.ProfilePeriod;
 import org.apache.metron.profiler.hbase.ColumnBuilder;
 import org.apache.metron.profiler.hbase.RowKeyBuilder;
-import org.apache.metron.profiler.hbase.SaltyRowKeyBuilder;
-import org.apache.metron.profiler.hbase.ValueOnlyColumnBuilder;
-import org.apache.metron.stellar.common.DefaultStellarStatefulExecutor;
-import org.apache.metron.stellar.common.StellarStatefulExecutor;
-import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
+import org.mockito.ArgumentCaptor;
 
+import java.io.IOException;
+import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.List;
 import java.util.Optional;
 import java.util.concurrent.TimeUnit;
 
 import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+import static org.mockito.Mockito.any;
+import static org.mockito.Mockito.eq;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
 
 /**
- * Tests the HBaseProfilerClient.
- *
- * The naming used in this test attempts to be as similar to how the 'groupBy'
- * functionality might be used 'in the wild'.  This test involves reading and
- * writing two separate groups originating from the same Profile and Entity.
- * There is a 'weekdays' group which contains all measurements taken on 
weekdays.
- * There is also a 'weekend' group which contains all measurements taken on 
weekends.
+ * Tests the {@link HBaseProfilerClient}.
  */
 public class HBaseProfilerClientTest {
-
   private static final String tableName = "profiler";
   private static final String columnFamily = "P";
+  private static final byte[] columnFamilyB = Bytes.toBytes(columnFamily);
+  private static final byte[] columnQualifier = Bytes.toBytes("column");
   private static final long periodDuration = 15;
   private static final TimeUnit periodUnits = TimeUnit.MINUTES;
   private static final int periodsPerHour = 4;
-
-  private HBaseProfilerClient client;
-  private StellarStatefulExecutor executor;
-  private MockHTable table;
-  private ProfileWriter profileWriter;
+  private static final byte[] expectedRowKey = Bytes.toBytes("some-row-key");
+  private static final String profileName = "profile1";
+  private static final String entityName = "entity1";
+  private static final int profileValue = 1231121;
+  private static final byte[] profileValueB = SerDeUtils.toBytes(profileValue);
+  private long periodDurationMillis = periodUnits.toMillis(periodDuration);
+
+  private HBaseClient hbaseClient;
+  private HBaseProfilerClient profilerClient;
+  private ProfileMeasurement expected;
+  private RowKeyBuilder rowKeyBuilder;
+  private ColumnBuilder columnBuilder;
+  private Result expectedResult;
+  private Result emptyResult;
 
   @Before
-  public void setup() throws Exception {
-    table = new MockHTable(tableName, columnFamily);
-    executor = new DefaultStellarStatefulExecutor();
-
-    // writes values to be read during testing
-    long periodDurationMillis = periodUnits.toMillis(periodDuration);
-    RowKeyBuilder rowKeyBuilder = new SaltyRowKeyBuilder();
-    ColumnBuilder columnBuilder = new ValueOnlyColumnBuilder(columnFamily);
-    profileWriter = new ProfileWriter(rowKeyBuilder, columnBuilder, table, 
periodDurationMillis);
-
-    client = new HBaseProfilerClient(table, rowKeyBuilder, columnBuilder, 
periodDurationMillis);
+  public void setup() {
+    // create a profile measurement used in the tests
+    expected = new ProfileMeasurement()
+            .withProfileName(profileName)
+            .withEntity(entityName)
+            .withPeriod(System.currentTimeMillis(), 5, TimeUnit.MINUTES)
+            .withProfileValue(profileValue);
+
+    // mock row key builder needs to return a row key for the profile 
measurement used in the tests
+    rowKeyBuilder = mock(RowKeyBuilder.class);
+    when(rowKeyBuilder.rowKey(any())).thenReturn(expectedRowKey);
+
+    // mock column builder - column family/qualifier comes from the column 
builder
+    columnBuilder = mock(ColumnBuilder.class);
+    when(columnBuilder.getColumnFamily()).thenReturn(columnFamily);
+    
when(columnBuilder.getColumnQualifier(eq("value"))).thenReturn(columnQualifier);
+
+    // this mock is used to feed data to the profiler client while testing
+    hbaseClient = mock(HBaseTableClient.class);
+
+    // a result that matches the expected profile measurement that can be 
return by the mock hbase client
+    expectedResult = mock(Result.class);
+    when(expectedResult.containsColumn(eq(columnFamilyB), 
eq(columnQualifier))).thenReturn(true);
+    when(expectedResult.getValue(eq(columnFamilyB), 
eq(columnQualifier))).thenReturn(profileValueB);
+
+    // an empty result to use in the tests
+    emptyResult = mock(Result.class);
+    when(emptyResult.containsColumn(any(), any())).thenReturn(false);
+
+    // create the profiler client that will be tested
+    profilerClient = new HBaseProfilerClient(hbaseClient, rowKeyBuilder, 
columnBuilder, periodDurationMillis);
   }
 
-  @After
-  public void tearDown() throws Exception {
-    table.clear();
+  @Test
 
 Review comment:
   These tests needed updated to continue to function. I re-did these tests 
because previously the test cases were focused on testing logic that does not 
actually live in the `HBaseProfilerClient`.  These tests now focus on 
exclusively testing the logic in `HBaseProfilerClient`, rather than logic 
performed elsewhere; like in the `ColumnBuilder` for instance.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to