public void ReturnsRow() { MockRepository mockRepository = new MockRepository(); IHBaseConnection connection = mockRepository.Stub<IHBaseConnection>(); IHBaseRowData rowData = mockRepository.Stub<IHBaseRowData>(); byte[] rowName = Encoding.UTF8.GetBytes("r"); byte[] tableName = Encoding.UTF8.GetBytes("t"); using (mockRepository.Record()) { SetupResult.For( connection .GetRow( tableName, rowName)) .Return(rowData); SetupResult.For(rowData.Columns).Return(new Dictionary<byte[], IList<IHBaseCellData>>()); SetupResult.For(rowData.Key).Return(rowName); } using (mockRepository.Playback()) { HBaseDatabase db = new HBaseDatabase(connection); HBaseTable table = new HBaseTable(tableName, db); var row = table.GetRow(rowName); Assert.Equal(rowName, row.Key); } }
public void LoadsOnLoad() { MockRepository mockRepository = new MockRepository(); IHBaseConnection connection = mockRepository.Stub<IHBaseConnection>(); IHBaseRowData rowData = mockRepository.Stub<IHBaseRowData>(); IHBaseCellData cellData = mockRepository.Stub<IHBaseCellData>(); byte[] tableName = Encoding.UTF8.GetBytes("t"); byte[] rowKey = Encoding.UTF8.GetBytes("r"); byte[] columnName = Encoding.UTF8.GetBytes("c"); using (mockRepository.Record()) { SetupResult.For(rowData.Key).Return(rowKey); SetupResult.For(rowData.Columns).Return(new Dictionary<byte[], IList<IHBaseCellData>> { { columnName, new List<IHBaseCellData> { cellData } } }); SetupResult.For(connection.GetRow(tableName, rowKey)).Return(rowData); } using (mockRepository.Playback()) { HBaseDatabase db = new HBaseDatabase(connection); HBaseRow row = new HBaseRow(Encoding.UTF8.GetBytes("r"), new HBaseTable(Encoding.UTF8.GetBytes("t"), db)); row.Load(); Assert.Equal(1, row.Columns.Keys.Count); } }
public void GetRowsRequiresRows() { MockRepository mockRepository = new MockRepository(); IHBaseConnection connection = mockRepository.Stub<IHBaseConnection>(); HBaseDatabase db = new HBaseDatabase(connection); HBaseTable table = new HBaseTable(Encoding.UTF8.GetBytes("stub"), db); Assert.Equal("rows", Assert.Throws<ArgumentNullException>(() => table.GetRows(null)).ParamName); Assert.Equal("rows", Assert.Throws<ArgumentException>(() => table.GetRows(new List<byte[]>())).ParamName); }
public void ClosesConnectionWhenClosed() { MockRepository mockRepository = new MockRepository(); IHBaseConnection connection = mockRepository.StrictMock<IHBaseConnection>(); using (mockRepository.Record()) { SetupResult.For(connection.IsOpen).Return(true); Expect.Call(connection.Close); } using (mockRepository.Playback()) { HBaseDatabase db = new HBaseDatabase(connection); db.Close(); } }
public void HasColumns() { MockRepository mockRepository = new MockRepository(); IHBaseConnection connection = mockRepository.Stub<IHBaseConnection>(); IHBaseRowData rowData = mockRepository.Stub<IHBaseRowData>(); HBaseDatabase db = new HBaseDatabase(connection); byte[] columnName = Encoding.UTF8.GetBytes("c"); using (mockRepository.Record()) { SetupResult.For(rowData.Key).Return(Encoding.UTF8.GetBytes("k")); SetupResult.For(rowData.Columns).Return(new Dictionary<byte[], IList<IHBaseCellData>>() { { columnName, new List<IHBaseCellData>() }}); } using (mockRepository.Playback()) { HBaseRow row = new HBaseRow(rowData, new HBaseTable(Encoding.UTF8.GetBytes("t"), db)); Assert.Contains(columnName, row.Columns.Keys); } }
public void LoadsOnLoad() { MockRepository mockRepository = new MockRepository(); IHBaseConnection connection = mockRepository.Stub<IHBaseConnection>(); IHBaseTableData tableData = mockRepository.Stub<IHBaseTableData>(); IHBaseColumnFamilyData cfd = mockRepository.Stub<IHBaseColumnFamilyData>(); using (mockRepository.Record()) { SetupResult.For(cfd.Name).Return(Encoding.UTF8.GetBytes("cf1")); SetupResult.For(tableData.Name).Return(Encoding.UTF8.GetBytes("t")); SetupResult.For(tableData.ColumnFamilies).Return(new Dictionary<byte[], IHBaseColumnFamilyData> { { Encoding.UTF8.GetBytes("cf1"), cfd } }); SetupResult.For(connection.GetTables()).Return(new List<IHBaseTableData> { tableData }); } using (mockRepository.Playback()) { HBaseDatabase db = new HBaseDatabase(connection); HBaseTable table = new HBaseTable(Encoding.UTF8.GetBytes("t"), db); table.Load(); Assert.Equal(1, table.ColumnFamilies.Keys.Count); } }
public void CreatesTable() { MockRepository mockRepository = new MockRepository(); IHBaseConnection connection = mockRepository.StrictMock<IHBaseConnection>(); IHBaseTableData tableData = mockRepository.Stub<IHBaseTableData>(); IHBaseColumnFamilyData columnFamilyData = mockRepository.Stub<IHBaseColumnFamilyData>(); using (mockRepository.Record()) { SetupResult.For(columnFamilyData.Name).Return(Encoding.UTF8.GetBytes("cf1")); SetupResult.For(tableData.Name).Return(Encoding.UTF8.GetBytes("t")); SetupResult.For(tableData.ColumnFamilies).Return(new Dictionary<byte[], IHBaseColumnFamilyData> { { Encoding.UTF8.GetBytes("cf1"), columnFamilyData } }); SetupResult.For(connection.IsOpen).Return(true); Expect.Call(() => connection.CreateTable(tableData)).IgnoreArguments().WhenCalled((mi) => { IHBaseTableData td = (IHBaseTableData)mi.Arguments[0]; Assert.Equal(tableData.Name, td.Name); Assert.Equal(tableData.ColumnFamilies.Count, td.ColumnFamilies.Count); Assert.Equal(tableData.ColumnFamilies.First().Value.Name, td.ColumnFamilies.First().Value.Name); }); } using (mockRepository.Playback()) { HBaseDatabase db = new HBaseDatabase(connection); HBaseTable table = new HBaseTable(Encoding.UTF8.GetBytes("t"), db); HBaseColumnFamily cf = new HBaseColumnFamily(Encoding.UTF8.GetBytes("cf1"), table); table.ColumnFamilies.Add(cf.Name, cf); db.CreateTable(table); } }
public void ReturnsRows() { MockRepository mockRepository = new MockRepository(); IHBaseConnection connection = mockRepository.Stub<IHBaseConnection>(); IList<IHBaseRowData> rowData = new List<IHBaseRowData>() { mockRepository.Stub<IHBaseRowData>() }; byte[] rowName = Encoding.UTF8.GetBytes("r"); byte[] columnName = Encoding.UTF8.GetBytes("r"); byte[] tableName = Encoding.UTF8.GetBytes("t"); using (mockRepository.Record()) { SetupResult.For( connection .GetRows( new List<byte[]> { rowName }, tableName, new List<byte[]> { columnName }, 123)) .Return(rowData); SetupResult.For(rowData[0].Columns).Return(new Dictionary<byte[], IList<IHBaseCellData>>()); SetupResult.For(rowData[0].Key).Return(rowName); } using (mockRepository.Playback()) { HBaseDatabase db = new HBaseDatabase(connection); HBaseTable table = new HBaseTable(tableName, db); var rows = table.GetRows( new List<byte[]> { rowName }, new List<byte[]> { columnName }, 123); Assert.Contains(rowName, rows.Select(r => r.Key).ToList()); } }
public void ScanReturnsRows() { MockRepository mockRepository = new MockRepository(); IHBaseConnection connection = mockRepository.Stub<IHBaseConnection>(); IHBaseRowData rowData1 = mockRepository.Stub<IHBaseRowData>(); IHBaseRowData rowData2 = mockRepository.Stub<IHBaseRowData>(); IHBaseRowData rowData3 = mockRepository.Stub<IHBaseRowData>(); HBaseDatabase db = new HBaseDatabase(connection); HBaseTable table = new HBaseTable(Encoding.UTF8.GetBytes("t"), db); byte[] startRow1 = Encoding.UTF8.GetBytes("start1"); byte[] startRow2 = Encoding.UTF8.GetBytes("start1"); byte[] startRow3 = Encoding.UTF8.GetBytes("start1"); byte[] stopRow = Encoding.UTF8.GetBytes("stop"); IList<byte[]> columns = new List<byte[]> { Encoding.UTF8.GetBytes("column") }; long? timestamp = 123; int? numRows = 400; using (mockRepository.Record()) { SetupResult.For(rowData1.Key).Return(startRow1); SetupResult.For(rowData1.Columns).Return(new Dictionary<byte[], IList<IHBaseCellData>>()); SetupResult.For(rowData2.Key).Return(startRow2); SetupResult.For(rowData2.Columns).Return(new Dictionary<byte[], IList<IHBaseCellData>>()); SetupResult.For(rowData3.Key).Return(startRow3); SetupResult.For(rowData3.Columns).Return(new Dictionary<byte[], IList<IHBaseCellData>>()); SetupResult.For(connection.Scan(table.Name, startRow1, columns, timestamp, numRows)).Return(new List<IHBaseRowData> { rowData1 }); SetupResult.For(connection.ScanWithStop(table.Name, startRow2, stopRow, columns, timestamp, numRows)).Return(new List<IHBaseRowData> { rowData2 }); SetupResult.For(connection.ScanWithPrefix(table.Name, startRow3, columns, numRows)).Return(new List<IHBaseRowData> { rowData3 }); } using (mockRepository.Playback()) { var rows = table.Scan(startRow1, columns, timestamp, numRows); Assert.Contains(startRow1, rows.Select(r => r.Key)); rows = table.ScanWithStop(startRow2, stopRow, columns, timestamp, numRows); Assert.Contains(startRow2, rows.Select(r => r.Key)); rows = table.ScanWithPrefix(startRow3, columns, numRows); Assert.Contains(startRow3, rows.Select(r => r.Key)); } }
public void ScanRequiresStopRow() { MockRepository mockRepository = new MockRepository(); IHBaseConnection connection = mockRepository.Stub<IHBaseConnection>(); HBaseDatabase db = new HBaseDatabase(connection); HBaseTable table = new HBaseTable(Encoding.UTF8.GetBytes("t"), db); Assert.Equal("stopRow", Assert.Throws<ArgumentNullException>(() => table.ScanWithStop(new byte[1], null, new List<byte[]> { new byte[1] })).ParamName); Assert.Equal("stopRow", Assert.Throws<ArgumentNullException>(() => table.ScanWithStop(new byte[1], new byte[0], new List<byte[]> { new byte[1] })).ParamName); }
public void DisablesTable() { MockRepository mockRepository = new MockRepository(); IHBaseConnection connection = mockRepository.StrictMock<IHBaseConnection>(); IHBaseTableData tableData = mockRepository.Stub<IHBaseTableData>(); byte[] tableName = Encoding.UTF8.GetBytes("t"); using (mockRepository.Record()) { SetupResult.For(connection.IsOpen).Return(true); SetupResult.For(tableData.Name).Return(tableName); Expect.Call(() => connection.DisableTable(tableName)); } using (mockRepository.Playback()) { HBaseDatabase db = new HBaseDatabase(connection); db.DisableTable(tableName); } }
public void ReturnsTables() { MockRepository mockRepository = new MockRepository(); IHBaseConnection connection = mockRepository.Stub<IHBaseConnection>(); IHBaseTableData table1 = mockRepository.Stub<IHBaseTableData>(); IHBaseTableData table2 = mockRepository.Stub<IHBaseTableData>(); IHBaseColumnFamilyData cf1 = mockRepository.Stub<IHBaseColumnFamilyData>(); IHBaseColumnFamilyData cf2 = mockRepository.Stub<IHBaseColumnFamilyData>(); using (mockRepository.Record()) { SetupResult.For(table1.Name).Return(Encoding.UTF8.GetBytes("table1")); SetupResult.For(table2.Name).Return(Encoding.UTF8.GetBytes("table2")); SetupResult.For(cf1.Name).Return(Encoding.UTF8.GetBytes("cf1")); SetupResult.For(cf2.Name).Return(Encoding.UTF8.GetBytes("cf2")); SetupResult.For(table1.ColumnFamilies).Return(new Dictionary<byte[], IHBaseColumnFamilyData> { { Encoding.UTF8.GetBytes("cf1"), cf1 } }); SetupResult.For(table2.ColumnFamilies).Return(new Dictionary<byte[], IHBaseColumnFamilyData> { { Encoding.UTF8.GetBytes("cf2"), cf2 } }); SetupResult.For(connection.GetTables()).Return(new List<IHBaseTableData> { table1, table2 }); } using (mockRepository.Playback()) { HBaseDatabase db = new HBaseDatabase(connection); var tables = db.GetTables(); Assert.Equal(2, tables.Count); Assert.Equal(Encoding.UTF8.GetBytes("table1"), tables[0].Name); Assert.Equal(Encoding.UTF8.GetBytes("table2"), tables[1].Name); Assert.Equal(1, tables[0].ColumnFamilies.Keys.Count); Assert.Equal(1, tables[1].ColumnFamilies.Keys.Count); Assert.Equal(Encoding.UTF8.GetBytes("cf1"), tables[0].ColumnFamilies.Values.Single().Name); Assert.Equal(Encoding.UTF8.GetBytes("cf2"), tables[1].ColumnFamilies.Values.Single().Name); } }
public void MutatesRows() { MockRepository mockRepository = new MockRepository(); IHBaseConnection connection = mockRepository.StrictMock<IHBaseConnection>(); Mutations.IHBaseMutation mutation = mockRepository.Stub<Mutations.IHBaseMutation>(); byte[] tableName = Encoding.UTF8.GetBytes("t"); byte[] row = Encoding.UTF8.GetBytes("r"); byte[] column = Encoding.UTF8.GetBytes("c"); mutation.Row = row; mutation.Column = column; using (mockRepository.Record()) { SetupResult.For(connection.IsOpen).Return(true); Expect.Call(() => connection.MutateRows(null, null, null)) .IgnoreArguments() .WhenCalled((mi) => { byte[] tableArg = (byte[])mi.Arguments[0]; IList<Protocols.IHBaseMutation> mutationArg = (IList<Protocols.IHBaseMutation>)mi.Arguments[1]; long? timestampArg = (long?)mi.Arguments[2]; Assert.Equal(tableName, tableArg); Assert.Equal(1, mutationArg.Count); Assert.Equal(123, timestampArg); }); } using (mockRepository.Playback()) { HBaseDatabase db = new HBaseDatabase(connection); db.MutateRows(tableName, new List<IHBaseMutation> { mutation }, 123); } }