コード例 #1
0
ファイル: HBaseTableTests.cs プロジェクト: nordbergm/HBaseNet
        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);
            }
        }
コード例 #2
0
ファイル: HBaseDatabase.cs プロジェクト: nordbergm/HBaseNet
        public void CreateTable(HBaseTable table)
        {
            if (table == null)
            {
                throw new ArgumentNullException("table");
            }

            Connection.CreateTable(table);
        }
コード例 #3
0
ファイル: HBaseTableTests.cs プロジェクト: nordbergm/HBaseNet
        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);
        }
コード例 #4
0
ファイル: HBaseTableTests.cs プロジェクト: nordbergm/HBaseNet
        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);
            }
        }
コード例 #5
0
        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);
            }
        }
コード例 #6
0
ファイル: HBaseTableTests.cs プロジェクト: nordbergm/HBaseNet
        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());
            }
        }
コード例 #7
0
ファイル: HBaseTableTests.cs プロジェクト: nordbergm/HBaseNet
        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));
            }
        }
コード例 #8
0
ファイル: HBaseTableTests.cs プロジェクト: nordbergm/HBaseNet
        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);
        }