├── .gitattributes
├── .gitignore
├── FxCopCustomDictionary.xml
├── LICENSE
├── Marlin.sln
├── Marlin.sln.DotSettings
├── Microsoft.HBase.Client.Tests
├── App.config
├── CellOperationsTests.cs
├── Clients
│ ├── GatewayClientTest.cs
│ ├── HBaseClientTestBase.cs
│ └── VNetClientTest.cs
├── ClusterCredentialsFactory.cs
├── ClusterCredentialsFactoryTests.cs
├── ClusterCredentialsTests.cs
├── FilterTestRecord.cs
├── FilterTests.cs
├── Microsoft.HBase.Client.Tests.csproj
├── Properties
│ └── AssemblyInfo.cs
├── PublicInternalArchitectureTests.cs
├── ScannerInformationTests.cs
├── Utilities
│ ├── AssertEqualityComparer.cs
│ ├── Catch.cs
│ ├── ContextSpecification.cs
│ ├── DisposableContextSpecification.cs
│ ├── EnumerableExtensions.cs
│ ├── GeneralComparisonOperator.cs
│ ├── ObjectExtensions.cs
│ ├── Pair.cs
│ ├── SecureStringExtensions.cs
│ ├── ShouldExtensionMethods.cs
│ ├── StringExtensions.cs
│ ├── TestAssemblyInitializeCleanup.cs
│ ├── TestBase.cs
│ ├── TestHelp.cs
│ └── TestRunMode.cs
├── VirtualNetworkLoadBalancerTests.cs
└── packages.config
├── Microsoft.HBase.Client.nuspec
├── Microsoft.HBase.Client
├── ClusterCredentials.cs
├── Exceptions
│ ├── ArgumentContainsNullException.cs
│ └── ArgumentEmptyException.cs
├── Filters
│ ├── BinaryComparator.cs
│ ├── BinaryPrefixComparator.cs
│ ├── BitComparator.cs
│ ├── ByteArrayComparable.cs
│ ├── ColumnCountGetFilter.cs
│ ├── ColumnPaginationFilter.cs
│ ├── ColumnPrefixFilter.cs
│ ├── ColumnRangeFilter.cs
│ ├── CompareFilter.cs
│ ├── DependentColumnFilter.cs
│ ├── FamilyFilter.cs
│ ├── Filter.cs
│ ├── FilterList.cs
│ ├── FirstKeyOnlyFilter.cs
│ ├── InclusiveStopFilter.cs
│ ├── KeyOnlyFilter.cs
│ ├── MultipleColumnPrefixFilter.cs
│ ├── NullComparator.cs
│ ├── PageFilter.cs
│ ├── PrefixFilter.cs
│ ├── QualifierFilter.cs
│ ├── RandomRowFilter.cs
│ ├── RegexStringComparator.cs
│ ├── RowFilter.cs
│ ├── SingleColumnValueExcludeFilter.cs
│ ├── SingleColumnValueFilter.cs
│ ├── SkipFilter.cs
│ ├── SubstringComparator.cs
│ ├── TimestampsFilter.cs
│ ├── ValueFilter.cs
│ └── WhileMatchFilter.cs
├── GlobalSuppressions.cs
├── HBaseClient.cs
├── IHBaseClient.cs
├── Internal
│ ├── ByteArrayEqualityComparer.cs
│ ├── Extensions
│ │ ├── ArgumentGuardExtensions.cs
│ │ ├── ObjectExtensions.cs
│ │ └── StringExtensions.cs
│ ├── Helpers
│ │ ├── DisposableHelp.cs
│ │ └── TaskHelpers.cs
│ └── ValidatedNotNullAttribute.cs
├── LoadBalancing
│ ├── Constants.cs
│ ├── IEndpointIgnorePolicy.cs
│ ├── ILoadBalancer.cs
│ ├── IgnoreFailedEndpointsPolicy.cs
│ └── LoadBalancerRoundRobin.cs
├── Microsoft.HBase.Client.csproj
├── Microsoft.HBase.Client.csproj.DotSettings
├── Properties
│ └── AssemblyInfo.cs
├── RequestOptions.cs
├── Requester
│ ├── GatewayWebRequester.cs
│ ├── IWebRequester.cs
│ └── VNetWebRequester.cs
├── ScannerInformation.cs
└── packages.config
├── Production.FxCop.ruleset
├── README.md
├── Test.FxCop.ruleset
├── TestSettings.testsettings
└── schemas
├── ProtoBuf
├── CellMessage.proto
├── CellSetMessage.proto
├── ColumnSchemaMessage.proto
├── Generated
│ ├── CellMessage.cs
│ ├── CellSetMessage.cs
│ ├── ColumnSchemaMessage.cs
│ ├── ScannerMessage.cs
│ ├── StorageClusterStatusMessage.cs
│ ├── TableInfoMessage.cs
│ ├── TableListMessage.cs
│ ├── TableSchemaMessage.cs
│ └── VersionMessage.cs
├── ProtoGen
│ ├── Licence.txt
│ ├── common.xslt
│ ├── csharp.xslt
│ ├── descriptor.proto
│ ├── protobuf-net.dll
│ ├── protobuf-net.xml
│ ├── protoc-license.txt
│ ├── protogen.exe
│ ├── protogen.exe.config
│ ├── vb.xslt
│ └── xml.xslt
├── ScannerMessage.proto
├── StorageClusterStatusMessage.proto
├── TableInfoMessage.proto
├── TableListMessage.proto
├── TableSchemaMessage.proto
└── VersionMessage.proto
└── XML
└── XMLSchema.xsd
/.gitattributes:
--------------------------------------------------------------------------------
1 | ###############################################################################
2 | # Set default behavior to automatically normalize line endings.
3 | ###############################################################################
4 | * text=auto
5 |
6 | ###############################################################################
7 | # Set default behavior for command prompt diff.
8 | #
9 | # This is need for earlier builds of msysgit that does not have it on by
10 | # default for csharp files.
11 | # Note: This is only used by command line
12 | ###############################################################################
13 | #*.cs diff=csharp
14 |
15 | ###############################################################################
16 | # Set the merge driver for project and solution files
17 | #
18 | # Merging from the command prompt will add diff markers to the files if there
19 | # are conflicts (Merging from VS is not affected by the settings below, in VS
20 | # the diff markers are never inserted). Diff markers may cause the following
21 | # file extensions to fail to load in VS. An alternative would be to treat
22 | # these files as binary and thus will always conflict and require user
23 | # intervention with every merge. To do so, just uncomment the entries below
24 | ###############################################################################
25 | #*.sln merge=binary
26 | #*.csproj merge=binary
27 | #*.vbproj merge=binary
28 | #*.vcxproj merge=binary
29 | #*.vcproj merge=binary
30 | #*.dbproj merge=binary
31 | #*.fsproj merge=binary
32 | #*.lsproj merge=binary
33 | #*.wixproj merge=binary
34 | #*.modelproj merge=binary
35 | #*.sqlproj merge=binary
36 | #*.wwaproj merge=binary
37 |
38 | ###############################################################################
39 | # behavior for image files
40 | #
41 | # image files are treated as binary by default.
42 | ###############################################################################
43 | #*.jpg binary
44 | #*.png binary
45 | #*.gif binary
46 |
47 | ###############################################################################
48 | # diff behavior for common document formats
49 | #
50 | # Convert binary document formats to text before diffing them. This feature
51 | # is only available from the command line. Turn it on by uncommenting the
52 | # entries below.
53 | ###############################################################################
54 | #*.doc diff=astextplain
55 | #*.DOC diff=astextplain
56 | #*.docx diff=astextplain
57 | #*.DOCX diff=astextplain
58 | #*.dot diff=astextplain
59 | #*.DOT diff=astextplain
60 | #*.pdf diff=astextplain
61 | #*.PDF diff=astextplain
62 | #*.rtf diff=astextplain
63 | #*.RTF diff=astextplain
64 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | ## Ignore Visual Studio temporary files, build results, and
2 | ## files generated by popular Visual Studio add-ons.
3 |
4 | #password files
5 | credentials.txt
6 |
7 | # User-specific files
8 | *.suo
9 | *.user
10 | *.sln.docstates
11 |
12 | # Build results
13 | [Dd]ebug/
14 | [Dd]ebugPublic/
15 | [Rr]elease/
16 | x64/
17 | build/
18 | bld/
19 | [Bb]in/
20 | [Oo]bj/
21 |
22 | # MSTest test Results
23 | [Tt]est[Rr]esult*/
24 | [Bb]uild[Ll]og.*
25 |
26 | #NUNIT
27 | *.VisualState.xml
28 | TestResult.xml
29 |
30 | # Build Results of an ATL Project
31 | [Dd]ebugPS/
32 | [Rr]eleasePS/
33 | dlldata.c
34 |
35 | *_i.c
36 | *_p.c
37 | *_i.h
38 | *.ilk
39 | *.meta
40 | *.obj
41 | *.pch
42 | *.pdb
43 | *.pgc
44 | *.pgd
45 | *.rsp
46 | *.sbr
47 | *.tlb
48 | *.tli
49 | *.tlh
50 | *.tmp
51 | *.tmp_proj
52 | *.log
53 | *.vspscc
54 | *.vssscc
55 | .builds
56 | *.pidb
57 | *.svclog
58 | *.scc
59 |
60 | # Chutzpah Test files
61 | _Chutzpah*
62 |
63 | # Visual C++ cache files
64 | ipch/
65 | *.aps
66 | *.ncb
67 | *.opensdf
68 | *.sdf
69 | *.cachefile
70 |
71 | # Visual Studio profiler
72 | *.psess
73 | *.vsp
74 | *.vspx
75 |
76 | # TFS 2012 Local Workspace
77 | $tf/
78 |
79 | # Guidance Automation Toolkit
80 | *.gpState
81 |
82 | # ReSharper is a .NET coding add-in
83 | _ReSharper*/
84 | *.[Rr]e[Ss]harper
85 | *.DotSettings.user
86 |
87 | # JustCode is a .NET coding addin-in
88 | .JustCode
89 |
90 | # TeamCity is a build add-in
91 | _TeamCity*
92 |
93 | # DotCover is a Code Coverage Tool
94 | *.dotCover
95 |
96 | # NCrunch
97 | *.ncrunch*
98 | _NCrunch_*
99 | .*crunch*.local.xml
100 |
101 | # MightyMoose
102 | *.mm.*
103 | AutoTest.Net/
104 |
105 | # Web workbench (sass)
106 | .sass-cache/
107 |
108 | # Installshield output folder
109 | [Ee]xpress/
110 |
111 | # DocProject is a documentation generator add-in
112 | DocProject/buildhelp/
113 | DocProject/Help/*.HxT
114 | DocProject/Help/*.HxC
115 | DocProject/Help/*.hhc
116 | DocProject/Help/*.hhk
117 | DocProject/Help/*.hhp
118 | DocProject/Help/Html2
119 | DocProject/Help/html
120 |
121 | # Click-Once directory
122 | publish/
123 |
124 | # Publish Web Output
125 | *.[Pp]ublish.xml
126 | *.azurePubxml
127 |
128 | # NuGet Packages Directory
129 | packages/
130 | ## TODO: If the tool you use requires repositories.config uncomment the next line
131 | #!packages/repositories.config
132 |
133 | # Enable "build/" folder in the NuGet Packages folder since NuGet packages use it for MSBuild targets
134 | # This line needs to be after the ignore of the build folder (and the packages folder if the line above has been uncommented)
135 | !packages/build/
136 |
137 | # Windows Azure Build Output
138 | csx/
139 | *.build.csdef
140 |
141 | # Windows Store app package directory
142 | AppPackages/
143 |
144 | # Others
145 | sql/
146 | *.Cache
147 | ClientBin/
148 | [Ss]tyle[Cc]op.*
149 | ~$*
150 | *~
151 | *.dbmdl
152 | *.dbproj.schemaview
153 | *.pfx
154 | *.publishsettings
155 | node_modules/
156 |
157 | # RIA/Silverlight projects
158 | Generated_Code/
159 |
160 | # Backup & report files from converting an old project file to a newer
161 | # Visual Studio version. Backup files are not needed, because we have git ;-)
162 | _UpgradeReport_Files/
163 | Backup*/
164 | UpgradeLog*.XML
165 | UpgradeLog*.htm
166 |
167 | # SQL Server files
168 | *.mdf
169 | *.ldf
170 |
171 | # Business Intelligence projects
172 | *.rdl.data
173 | *.bim.layout
174 | *.bim_*.settings
175 |
176 | # Microsoft Fakes
177 | FakesAssemblies/
178 |
179 | #Roslyn caches
180 | .vs/
181 |
182 | #GhostDoc files
183 | *.sln.GhostDoc.xml
--------------------------------------------------------------------------------
/FxCopCustomDictionary.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
11 |
12 |
13 |
14 |
22 |
23 | headnode
24 |
25 |
26 |
32 |
33 |
34 |
35 |
48 |
49 |
50 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
--------------------------------------------------------------------------------
/Marlin.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio 2013
4 | VisualStudioVersion = 12.0.40629.0
5 | MinimumVisualStudioVersion = 10.0.40219.1
6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.HBase.Client", "Microsoft.HBase.Client\Microsoft.HBase.Client.csproj", "{256F1A52-D499-4086-83B4-AE13A515AE1D}"
7 | EndProject
8 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.HBase.Client.Tests", "Microsoft.HBase.Client.Tests\Microsoft.HBase.Client.Tests.csproj", "{30A575C3-71C8-4D13-91E0-6AE0359C6A8D}"
9 | EndProject
10 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{6A268A29-9EE7-4AA3-A29D-CDD7B6EC96C6}"
11 | ProjectSection(SolutionItems) = preProject
12 | Production.FxCop.ruleset = Production.FxCop.ruleset
13 | Test.FxCop.ruleset = Test.FxCop.ruleset
14 | TestSettings.testsettings = TestSettings.testsettings
15 | EndProjectSection
16 | EndProject
17 | Global
18 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
19 | Debug|Any CPU = Debug|Any CPU
20 | Release|Any CPU = Release|Any CPU
21 | EndGlobalSection
22 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
23 | {256F1A52-D499-4086-83B4-AE13A515AE1D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
24 | {256F1A52-D499-4086-83B4-AE13A515AE1D}.Debug|Any CPU.Build.0 = Debug|Any CPU
25 | {256F1A52-D499-4086-83B4-AE13A515AE1D}.Release|Any CPU.ActiveCfg = Release|Any CPU
26 | {256F1A52-D499-4086-83B4-AE13A515AE1D}.Release|Any CPU.Build.0 = Release|Any CPU
27 | {30A575C3-71C8-4D13-91E0-6AE0359C6A8D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
28 | {30A575C3-71C8-4D13-91E0-6AE0359C6A8D}.Debug|Any CPU.Build.0 = Debug|Any CPU
29 | {30A575C3-71C8-4D13-91E0-6AE0359C6A8D}.Release|Any CPU.ActiveCfg = Release|Any CPU
30 | {30A575C3-71C8-4D13-91E0-6AE0359C6A8D}.Release|Any CPU.Build.0 = Release|Any CPU
31 | EndGlobalSection
32 | GlobalSection(SolutionProperties) = preSolution
33 | HideSolutionNode = FALSE
34 | EndGlobalSection
35 | GlobalSection(ExtensibilityGlobals) = postSolution
36 | EnterpriseLibraryConfigurationToolBinariesPathV6 = packages\EnterpriseLibrary.TransientFaultHandling.6.0.1304.0\lib\portable-net45+win+wp8
37 | EndGlobalSection
38 | EndGlobal
39 |
--------------------------------------------------------------------------------
/Microsoft.HBase.Client.Tests/App.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
--------------------------------------------------------------------------------
/Microsoft.HBase.Client.Tests/Clients/VNetClientTest.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation
2 | // All rights reserved.
3 | //
4 | // Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 | // use this file except in compliance with the License. You may obtain a copy
6 | // of the License at http://www.apache.org/licenses/LICENSE-2.0
7 | //
8 | // THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
9 | // KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
10 | // WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
11 | // MERCHANTABLITY OR NON-INFRINGEMENT.
12 | //
13 | // See the Apache Version 2.0 License for specific language governing
14 | // permissions and limitations under the License.
15 |
16 | namespace Microsoft.HBase.Client.Tests.Clients
17 | {
18 | using System.Collections.Generic;
19 | using Microsoft.HBase.Client.LoadBalancing;
20 | using Microsoft.Practices.EnterpriseLibrary.TransientFaultHandling;
21 | using Microsoft.VisualStudio.TestTools.UnitTesting;
22 | using Microsoft.HBase.Client.Tests.Utilities;
23 | using org.apache.hadoop.hbase.rest.protobuf.generated;
24 | using System.Linq;
25 | using System;
26 | using System.Text;
27 | [TestClass]
28 | public class VNetClientTest : HBaseClientTestBase
29 | {
30 | public override IHBaseClient CreateClient()
31 | {
32 | var regionServerIPs = new List();
33 | // TODO automatically retrieve IPs from Ambari REST APIs
34 | regionServerIPs.Add("10.17.0.11");
35 | regionServerIPs.Add("10.17.0.13");
36 |
37 | var options = RequestOptions.GetDefaultOptions();
38 | options.Port = 8090;
39 | options.AlternativeEndpoint = "";
40 |
41 | return new HBaseClient(null, options, new LoadBalancerRoundRobin(regionServerIPs));
42 | }
43 |
44 | [TestMethod]
45 | [TestCategory(TestRunMode.CheckIn)]
46 | public override void TestFullScan()
47 | {
48 | var client = CreateClient();
49 |
50 | StoreTestData(client);
51 | var expectedSet = new HashSet(Enumerable.Range(0, 100));
52 | IEnumerable cells = client.StatelessScannerAsync(testTableName).Result;
53 | foreach (CellSet cell in cells)
54 | {
55 | foreach (CellSet.Row row in cell.rows)
56 | {
57 | int k = BitConverter.ToInt32(row.key, 0);
58 | expectedSet.Remove(k);
59 | }
60 | }
61 | Assert.AreEqual(0, expectedSet.Count, "The expected set wasn't empty! Items left {0}!", string.Join(",", expectedSet));
62 | }
63 |
64 | [TestMethod]
65 | [TestCategory(TestRunMode.CheckIn)]
66 | public override void TestSubsetScan()
67 | {
68 | var client = CreateClient();
69 | const int startRow = 10;
70 | const int endRow = 10 + 5;
71 | StoreTestData(client);
72 | var expectedSet = new HashSet(Enumerable.Range(startRow, endRow - startRow));
73 | // TODO how to change rowkey to internal hbase binary string
74 | IEnumerable cells = client.StatelessScannerAsync(testTableName, "", "startrow=\x0A\x00\x00\x00&endrow=\x0F\x00\x00\x00").Result;
75 |
76 | foreach (CellSet cell in cells)
77 | {
78 | foreach (CellSet.Row row in cell.rows)
79 | {
80 | int k = BitConverter.ToInt32(row.key, 0);
81 | expectedSet.Remove(k);
82 | }
83 | }
84 | Assert.AreEqual(0, expectedSet.Count, "The expected set wasn't empty! Items left {0}!", string.Join(",", expectedSet));
85 | }
86 |
87 | [TestMethod]
88 | [TestCategory(TestRunMode.CheckIn)]
89 | public void TestCellsMultiVersionGet()
90 | {
91 | const string testKey = "content";
92 | const string testValue = "the force is strong in this column";
93 | var client = CreateClient();
94 | var set = new CellSet();
95 | var row = new CellSet.Row { key = Encoding.UTF8.GetBytes(testKey) };
96 | set.rows.Add(row);
97 |
98 | var value = new Cell { column = Encoding.UTF8.GetBytes("d:starwars"), data = Encoding.UTF8.GetBytes(testValue) };
99 | row.values.Add(value);
100 |
101 | client.StoreCellsAsync(testTableName, set).Wait();
102 | client.StoreCellsAsync(testTableName, set).Wait();
103 | CellSet cell = client.GetCellsAsync(testTableName, testKey, "d:starwars", "3").Result;
104 | Assert.AreEqual(2, cell.rows[0].values.Count);
105 | }
106 | }
107 | }
108 |
--------------------------------------------------------------------------------
/Microsoft.HBase.Client.Tests/ClusterCredentialsFactory.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation
2 | // All rights reserved.
3 | //
4 | // Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 | // use this file except in compliance with the License. You may obtain a copy
6 | // of the License at http://www.apache.org/licenses/LICENSE-2.0
7 | //
8 | // THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
9 | // KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
10 | // WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
11 | // MERCHANTABLITY OR NON-INFRINGEMENT.
12 | //
13 | // See the Apache Version 2.0 License for specific language governing
14 | // permissions and limitations under the License.
15 |
16 | namespace Microsoft.HBase.Client.Tests
17 | {
18 | using System;
19 | using System.Collections.Generic;
20 | using System.Globalization;
21 | using System.IO;
22 | using System.Linq;
23 | using Microsoft.HBase.Client.Internal;
24 |
25 | internal static class ClusterCredentialsFactory
26 | {
27 | ///
28 | /// Reads the cluster credentials from a file found under the given path.
29 | /// This file needs to contain exactly three lines, where the first is the cluster URI, the second the username and the third is the password.
30 | /// (Bad luck if your username/password contains either \r or \n!).
31 | ///
32 | /// A possible example is:
33 | ///
34 | /// https://csharpazurehbase.azurehdinsight.net/
35 | /// admin
36 | /// _mySup3rS4f3P4ssW0rd.
37 | ///
38 | ///
39 | /// a file system path that contains a text file with the credentials
40 | /// a ClusterCredentials object with the cluster URI, user and the password
41 | internal static ClusterCredentials CreateFromFile(string path)
42 | {
43 | path.ArgumentNotNull("path");
44 |
45 | List lines = File.ReadAllLines(path).ToList();
46 | return CreateFromList(lines);
47 | }
48 |
49 | internal static ClusterCredentials CreateFromList(List lines)
50 | {
51 | lines.ArgumentNotNull("lines");
52 |
53 | if (lines.Count() != 3)
54 | {
55 | throw new ArgumentException(
56 | string.Format(
57 | CultureInfo.InvariantCulture,
58 | "Expected the credentials file to have exactly three lines, " +
59 | "first containing the cluster URL, second the username, third the password. " + "Given {0} lines!",
60 | lines.Count()),
61 | "lines");
62 | }
63 |
64 | var rv = new ClusterCredentials(new Uri(lines[0]), lines[1], lines[2]);
65 | return rv;
66 | }
67 | }
68 | }
69 |
--------------------------------------------------------------------------------
/Microsoft.HBase.Client.Tests/ClusterCredentialsFactoryTests.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation
2 | // All rights reserved.
3 | //
4 | // Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 | // use this file except in compliance with the License. You may obtain a copy
6 | // of the License at http://www.apache.org/licenses/LICENSE-2.0
7 | //
8 | // THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
9 | // KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
10 | // WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
11 | // MERCHANTABLITY OR NON-INFRINGEMENT.
12 | //
13 | // See the Apache Version 2.0 License for specific language governing
14 | // permissions and limitations under the License.
15 |
16 | namespace Microsoft.HBase.Client.Tests
17 | {
18 | using System;
19 | using System.Collections.Generic;
20 | using System.IO;
21 | using Microsoft.HBase.Client.Internal;
22 | using Microsoft.HBase.Client.Tests.Utilities;
23 | using Microsoft.VisualStudio.TestTools.UnitTesting;
24 |
25 | // ReSharper disable InconsistentNaming
26 |
27 | [TestClass]
28 | public class When_I_call_ClusterCredentialsFactory_CreateFromList : DisposableContextSpecification
29 | {
30 | [TestMethod]
31 | [TestCategory(TestRunMode.CheckIn)]
32 | public void It_should_throw_when_the_list_is_null()
33 | {
34 | var ane =
35 | (ArgumentNullException)
36 | typeof(ArgumentNullException).ShouldBeThrownBy(() => DisposableHelp.SafeCreate(() => ClusterCredentialsFactory.CreateFromList(null)));
37 | ane.ParamName.ShouldEqual("lines");
38 | }
39 |
40 | [TestMethod]
41 | [TestCategory(TestRunMode.CheckIn)]
42 | public void It_should_throw_when_the_list_is_too_long()
43 | {
44 | var lst = new List { Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), Guid.NewGuid().ToString() };
45 | var ae =
46 | (ArgumentException)
47 | typeof(ArgumentException).ShouldBeThrownBy(() => DisposableHelp.SafeCreate(() => ClusterCredentialsFactory.CreateFromList(lst)));
48 | ae.ParamName.ShouldEqual("lines");
49 | }
50 |
51 | [TestMethod]
52 | [TestCategory(TestRunMode.CheckIn)]
53 | public void It_should_throw_when_the_list_is_too_short()
54 | {
55 | var lst = new List();
56 |
57 | // empty
58 | var ae =
59 | (ArgumentException)
60 | typeof(ArgumentException).ShouldBeThrownBy(() => DisposableHelp.SafeCreate(() => ClusterCredentialsFactory.CreateFromList(lst)));
61 | ae.ParamName.ShouldEqual("lines");
62 |
63 | // one
64 | lst.Add(Guid.NewGuid().ToString());
65 | ae =
66 | (ArgumentException)
67 | typeof(ArgumentException).ShouldBeThrownBy(() => DisposableHelp.SafeCreate(() => ClusterCredentialsFactory.CreateFromList(lst)));
68 | ae.ParamName.ShouldEqual("lines");
69 |
70 | // two
71 | lst.Add(Guid.NewGuid().ToString());
72 | ae =
73 | (ArgumentException)
74 | typeof(ArgumentException).ShouldBeThrownBy(() => DisposableHelp.SafeCreate(() => ClusterCredentialsFactory.CreateFromList(lst)));
75 | ae.ParamName.ShouldEqual("lines");
76 | }
77 | }
78 |
79 |
80 | [TestClass]
81 | public class When_I_call_ClusterCredentialsFactory_CreateFromFile
82 | {
83 | [TestMethod]
84 | [TestCategory(TestRunMode.CheckIn)]
85 | public void It_should_throw_the_file_does_not_exist()
86 | {
87 | string path = Path.Combine(Directory.GetCurrentDirectory(), Guid.NewGuid().ToString());
88 | var fnfe =
89 | (FileNotFoundException)
90 | typeof(FileNotFoundException).ShouldBeThrownBy(() => DisposableHelp.SafeCreate(() => ClusterCredentialsFactory.CreateFromFile(path)));
91 | fnfe.FileName.ShouldEqual(path);
92 | }
93 |
94 | [TestMethod]
95 | [TestCategory(TestRunMode.CheckIn)]
96 | public void It_should_throw_when_the_path_is_null()
97 | {
98 | var ane =
99 | (ArgumentNullException)
100 | typeof(ArgumentNullException).ShouldBeThrownBy(() => DisposableHelp.SafeCreate(() => ClusterCredentialsFactory.CreateFromFile(null)));
101 | ane.ParamName.ShouldEqual("path");
102 | }
103 | }
104 | }
105 |
--------------------------------------------------------------------------------
/Microsoft.HBase.Client.Tests/FilterTestRecord.cs:
--------------------------------------------------------------------------------
1 | namespace Microsoft.HBase.Client.Tests
2 | {
3 | using System;
4 | using Microsoft.HBase.Client.Internal;
5 |
6 | internal static class FilterTestRecordExtensions
7 | {
8 | internal static FilterTestRecord WithAValue(this FilterTestRecord value, string a)
9 | {
10 | value.ArgumentNotNull("value");
11 | return new FilterTestRecord(value.RowKey, value.LineNumber, a, value.B);
12 | }
13 |
14 | internal static FilterTestRecord WithBValue(this FilterTestRecord value, string b)
15 | {
16 | value.ArgumentNotNull("value");
17 | return new FilterTestRecord(value.RowKey, value.LineNumber, value.A, b);
18 | }
19 |
20 | internal static FilterTestRecord WithLineNumberValue(this FilterTestRecord value, int lineNumber)
21 | {
22 | value.ArgumentNotNull("value");
23 | return new FilterTestRecord(value.RowKey, lineNumber, value.A, value.B);
24 | }
25 | }
26 |
27 | internal class FilterTestRecord : IEquatable
28 | {
29 | internal FilterTestRecord(string rowKey, int lineNumber, string a, string b)
30 | {
31 | RowKey = rowKey;
32 | LineNumber = lineNumber;
33 | A = a;
34 | B = b;
35 | }
36 |
37 | internal string A { get; private set; }
38 |
39 | internal string B { get; private set; }
40 |
41 | internal int LineNumber { get; private set; }
42 |
43 | internal string RowKey { get; private set; }
44 |
45 | public bool Equals(FilterTestRecord other)
46 | {
47 | if (ReferenceEquals(null, other))
48 | {
49 | return false;
50 | }
51 | return LineNumber == other.LineNumber && string.Equals(A, other.A) && string.Equals(RowKey, other.RowKey) && string.Equals(B, other.B);
52 | }
53 |
54 | public override bool Equals(object obj)
55 | {
56 | return Equals(obj as FilterTestRecord);
57 | }
58 |
59 | public override int GetHashCode()
60 | {
61 | unchecked
62 | {
63 | int hashCode = LineNumber;
64 | hashCode = (hashCode * 397) ^ (A != null ? A.GetHashCode() : 0);
65 | hashCode = (hashCode * 397) ^ (RowKey != null ? RowKey.GetHashCode() : 0);
66 | hashCode = (hashCode * 397) ^ (B != null ? B.GetHashCode() : 0);
67 | return hashCode;
68 | }
69 | }
70 |
71 | public override string ToString()
72 | {
73 | return string.Format("RowKey: {0}, LineNumber: {1}, A: {2}, B: {3}", RowKey, LineNumber, A, B);
74 | }
75 |
76 | public static bool operator ==(FilterTestRecord left, FilterTestRecord right)
77 | {
78 | return Equals(left, right);
79 | }
80 |
81 | public static bool operator !=(FilterTestRecord left, FilterTestRecord right)
82 | {
83 | return !Equals(left, right);
84 | }
85 | }
86 | }
--------------------------------------------------------------------------------
/Microsoft.HBase.Client.Tests/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation
2 | // All rights reserved.
3 | //
4 | // Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 | // use this file except in compliance with the License. You may obtain a copy
6 | // of the License at http://www.apache.org/licenses/LICENSE-2.0
7 | //
8 | // THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
9 | // KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
10 | // WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
11 | // MERCHANTABLITY OR NON-INFRINGEMENT.
12 | //
13 | // See the Apache Version 2.0 License for specific language governing
14 | // permissions and limitations under the License.
15 |
16 | using System;
17 | using System.Reflection;
18 | using System.Runtime.InteropServices;
19 |
20 | [assembly: AssemblyTitle("Microsoft.HBase.Client.Tests")]
21 | [assembly: AssemblyDescription("")]
22 | [assembly: AssemblyConfiguration("")]
23 | [assembly: AssemblyCompany("Microsoft Corporation")]
24 | [assembly: AssemblyProduct("Microsoft.HBase.Client.Tests")]
25 | [assembly: AssemblyCopyright("Copyright © Microsoft Corporation 2014")]
26 | [assembly: AssemblyTrademark("")]
27 | [assembly: AssemblyCulture("")]
28 | [assembly: ComVisible(false)]
29 | [assembly: CLSCompliant(true)]
30 | [assembly: AssemblyVersion("1.0.0.0")]
31 | [assembly: AssemblyFileVersion("1.0.0.0")]
32 |
--------------------------------------------------------------------------------
/Microsoft.HBase.Client.Tests/PublicInternalArchitectureTests.cs:
--------------------------------------------------------------------------------
1 | namespace Microsoft.HBase.Client.Tests
2 | {
3 | using System;
4 | using System.Collections.Generic;
5 | using System.Linq;
6 | using System.Reflection;
7 | using Microsoft.HBase.Client.Tests.Utilities;
8 | using Microsoft.VisualStudio.TestTools.UnitTesting;
9 |
10 | // ReSharper disable InconsistentNaming
11 | //
12 | [TestClass]
13 | public class PublicInternalArchitecturalTests:TestBase
14 | {
15 | [TestMethod]
16 | [TestCategory(TestRunMode.CheckIn)]
17 | public void All_declarations_not_under_an_internal_or_resources_namespace_are_public_or_nested()
18 | {
19 | List assemblies = GetAssembliesUnderTest().ToList();
20 | assemblies.Count.ShouldBeGreaterThan(0);
21 |
22 | var violatingTypes = new HashSet();
23 |
24 | foreach (Assembly asm in assemblies)
25 | {
26 | List allAssemblyTypes = asm.GetTypes().ToList();
27 | foreach (Type type in allAssemblyTypes)
28 | {
29 | string namespaceName = type.Namespace ?? string.Empty;
30 | if (namespaceName.Length == 0)
31 | {
32 | // skip anonymous types.
33 | continue;
34 | }
35 |
36 | if (namespaceName == "JetBrains.Profiler.Core.Instrumentation" && type.Name == "DataOnStack")
37 | {
38 | // appears when performing test coverage using dotCover.
39 | continue;
40 | }
41 |
42 | if (!namespaceName.Contains(".Internal") && !namespaceName.Contains(".Resources") && !type.IsPublic && !type.IsNested)
43 | {
44 | violatingTypes.Add(type);
45 | }
46 | }
47 | }
48 |
49 | violatingTypes.ShouldContainOnly(new Type[] { });
50 | }
51 |
52 | [TestMethod]
53 | [TestCategory(TestRunMode.CheckIn)]
54 | public void All_declarations_under_an_internal_namespace_are_not_public()
55 | {
56 | List assemblies = GetAssembliesUnderTest().ToList();
57 | assemblies.Count.ShouldBeGreaterThan(0);
58 |
59 | var violatingTypes = new HashSet();
60 |
61 | foreach (Assembly asm in assemblies)
62 | {
63 | List allAssemblyTypes = asm.GetTypes().ToList();
64 | foreach (Type type in allAssemblyTypes)
65 | {
66 | string namespaceName = type.Namespace ?? string.Empty;
67 | if (namespaceName.Contains(".Internal") && type.IsPublic)
68 | {
69 | violatingTypes.Add(type);
70 | }
71 | }
72 | }
73 |
74 | violatingTypes.ShouldContainOnly(new Type[] { });
75 | }
76 | }
77 | }
78 |
--------------------------------------------------------------------------------
/Microsoft.HBase.Client.Tests/ScannerInformationTests.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation
2 | // All rights reserved.
3 | //
4 | // Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 | // use this file except in compliance with the License. You may obtain a copy
6 | // of the License at http://www.apache.org/licenses/LICENSE-2.0
7 | //
8 | // THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
9 | // KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
10 | // WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
11 | // MERCHANTABLITY OR NON-INFRINGEMENT.
12 | //
13 | // See the Apache Version 2.0 License for specific language governing
14 | // permissions and limitations under the License.
15 |
16 | namespace Microsoft.HBase.Client.Tests
17 | {
18 | using System;
19 | using System.Net;
20 | using Microsoft.HBase.Client.Tests.Utilities;
21 | using Microsoft.VisualStudio.TestTools.UnitTesting;
22 |
23 | // ReSharper disable InconsistentNaming
24 |
25 | [TestClass]
26 | public class When_I_create_ScannerInformation : ContextSpecification
27 | {
28 | private const string expectedScannerId = "/140614753560332aa73e8";
29 | private const string expectedTableName = "mytable";
30 | private readonly Uri expectedLocation = new Uri("https://headnodehost:8090/" + expectedTableName + "/scanner" + expectedScannerId);
31 | private ScannerInformation target;
32 |
33 | protected override void Context()
34 | {
35 | target = new ScannerInformation(expectedLocation, expectedTableName, new WebHeaderCollection());
36 | }
37 |
38 | [TestMethod]
39 | [TestCategory(TestRunMode.CheckIn)]
40 | public void It_should_have_the_expected_location()
41 | {
42 | target.Location.ShouldEqual(expectedLocation);
43 | }
44 |
45 | [TestMethod]
46 | [TestCategory(TestRunMode.CheckIn)]
47 | public void It_should_have_the_expected_scanner_identifier()
48 | {
49 | target.ScannerId.ShouldEqual(expectedScannerId.Substring(1));
50 | }
51 |
52 | [TestMethod]
53 | [TestCategory(TestRunMode.CheckIn)]
54 | public void It_should_have_the_expected_table_name()
55 | {
56 | target.TableName.ShouldEqual(expectedTableName);
57 | }
58 | }
59 |
60 | [TestClass]
61 | public class When_I_call_a_ScannerInformation_ctor : ContextSpecification
62 | {
63 | private const string validTableName = "mytable";
64 | private readonly Uri validLocation = new Uri("https://headnodehost:8090/" + validTableName + "/scanner/140614753560332aa73e8");
65 |
66 | [TestMethod]
67 | [TestCategory(TestRunMode.CheckIn)]
68 | public void It_should_reject_empty_table_names()
69 | {
70 | object instance = null;
71 | typeof(ArgumentEmptyException).ShouldBeThrownBy(() => instance = new ScannerInformation(validLocation, string.Empty, new WebHeaderCollection()));
72 | instance.ShouldBeNull();
73 | }
74 |
75 | [TestMethod]
76 | [TestCategory(TestRunMode.CheckIn)]
77 | public void It_should_reject_null_locations()
78 | {
79 | object instance = null;
80 | typeof(ArgumentNullException).ShouldBeThrownBy(() => instance = new ScannerInformation(null, validTableName, new WebHeaderCollection()));
81 | instance.ShouldBeNull();
82 | }
83 |
84 | [TestMethod]
85 | [TestCategory(TestRunMode.CheckIn)]
86 | public void It_should_reject_null_table_names()
87 | {
88 | object instance = null;
89 | typeof(ArgumentNullException).ShouldBeThrownBy(() => instance = new ScannerInformation(validLocation, null, new WebHeaderCollection()));
90 | instance.ShouldBeNull();
91 | }
92 | }
93 | }
94 |
--------------------------------------------------------------------------------
/Microsoft.HBase.Client.Tests/Utilities/Catch.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation
2 | // All rights reserved.
3 | //
4 | // Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 | // use this file except in compliance with the License. You may obtain a copy
6 | // of the License at http://www.apache.org/licenses/LICENSE-2.0
7 | //
8 | // THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
9 | // KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
10 | // WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
11 | // MERCHANTABLITY OR NON-INFRINGEMENT.
12 | //
13 | // See the Apache Version 2.0 License for specific language governing
14 | // permissions and limitations under the License.
15 |
16 | namespace Microsoft.HBase.Client.Tests.Utilities
17 | {
18 | using System;
19 | using System.Diagnostics.CodeAnalysis;
20 |
21 | ///
22 | /// Catches exception thrown by an action.
23 | ///
24 | ///
25 | /// Originally borrowed from Machine.Specifications, licensed under MS-PL.
26 | ///
27 | internal static class Catch
28 | {
29 | ///
30 | /// Executes and action, capturing the thrown exception if any.
31 | ///
32 | ///
33 | /// The action to execute.
34 | ///
35 | ///
36 | /// The thrown exception; otherwise null.
37 | ///
38 | [SuppressMessage("Microsoft.Design", "CA1031:DoNotCatchGeneralExceptionTypes", Justification = "This is a testing utility (MWP).")]
39 | internal static Exception Exception(Action throwingAction)
40 | {
41 | try
42 | {
43 | throwingAction();
44 | }
45 | catch (Exception exception)
46 | {
47 | return exception;
48 | }
49 |
50 | return null;
51 | }
52 | }
53 | }
54 |
--------------------------------------------------------------------------------
/Microsoft.HBase.Client.Tests/Utilities/ContextSpecification.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation
2 | // All rights reserved.
3 | //
4 | // Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 | // use this file except in compliance with the License. You may obtain a copy
6 | // of the License at http://www.apache.org/licenses/LICENSE-2.0
7 | //
8 | // THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
9 | // KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
10 | // WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
11 | // MERCHANTABLITY OR NON-INFRINGEMENT.
12 | //
13 | // See the Apache Version 2.0 License for specific language governing
14 | // permissions and limitations under the License.
15 |
16 | namespace Microsoft.HBase.Client.Tests.Utilities
17 | {
18 | using Microsoft.VisualStudio.TestTools.UnitTesting;
19 |
20 | ///
21 | /// Provides common services for BDD-style (context/specification) unit tests.
22 | /// Serves as an adapter between the MSTest framework and our BDD-style tests.
23 | ///
24 | //// Borrowed from the blog of SaintGimp (with permission).
25 | [TestClass]
26 | public abstract class ContextSpecification : TestBase
27 | {
28 | ///
29 | /// Sets up the environment for a specification context.
30 | ///
31 | protected virtual void Context()
32 | {
33 | }
34 |
35 | ///
36 | /// Acts on the context to create the observable condition.
37 | ///
38 | protected virtual void BecauseOf()
39 | {
40 | }
41 |
42 | ///
43 | [TestInitialize]
44 | public override void TestInitialize()
45 | {
46 | base.TestInitialize();
47 |
48 | Context();
49 | BecauseOf();
50 | }
51 | }
52 | }
53 |
--------------------------------------------------------------------------------
/Microsoft.HBase.Client.Tests/Utilities/DisposableContextSpecification.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation
2 | // All rights reserved.
3 | //
4 | // Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 | // use this file except in compliance with the License. You may obtain a copy
6 | // of the License at http://www.apache.org/licenses/LICENSE-2.0
7 | //
8 | // THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
9 | // KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
10 | // WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
11 | // MERCHANTABLITY OR NON-INFRINGEMENT.
12 | //
13 | // See the Apache Version 2.0 License for specific language governing
14 | // permissions and limitations under the License.
15 |
16 | namespace Microsoft.HBase.Client.Tests.Utilities
17 | {
18 | using System;
19 | using System.Collections.Generic;
20 | using System.Diagnostics.CodeAnalysis;
21 | using System.Reflection;
22 | using System.Threading;
23 | using Microsoft.VisualStudio.TestTools.UnitTesting;
24 |
25 | ///
26 | /// A that implements .
27 | ///
28 | [TestClass]
29 | public abstract class DisposableContextSpecification : ContextSpecification, IDisposable
30 | {
31 | private int _disposed;
32 |
33 | ///
34 | [SuppressMessage("Microsoft.Design", "CA1063:ImplementIDisposableCorrectly")]
35 | public void Dispose()
36 | {
37 | if (Interlocked.Exchange(ref _disposed, 1) != 0)
38 | {
39 | // already disposed or disposing
40 | return;
41 | }
42 |
43 | Dispose(true);
44 |
45 | // Use SupressFinalize in case a subclass of this type implements a finalizer.
46 | GC.SuppressFinalize(this);
47 | }
48 |
49 | ///
50 | /// Releases unmanaged and - optionally - managed resources.
51 | ///
52 | ///
53 | /// Use true to release both managed and unmanaged resources; false to release only unmanaged resources.
54 | ///
55 | protected virtual void Dispose(bool disposing)
56 | {
57 | if (disposing)
58 | {
59 | Type derrivedType = GetType();
60 | FieldInfo[] fields = derrivedType.GetFields();
61 | foreach (FieldInfo field in fields)
62 | {
63 | object value = field.GetValue(this);
64 | if (value.IsNotNull())
65 | {
66 | Type valueType = value.GetType();
67 | if (!valueType.IsValueType)
68 | {
69 | var asCollectionOfDisposables = value as IEnumerable;
70 | if (!ReferenceEquals(asCollectionOfDisposables, null))
71 | {
72 | foreach (IDisposable disposable in asCollectionOfDisposables)
73 | {
74 | disposable.Dispose();
75 | }
76 | }
77 |
78 | var asDisposable = value as IDisposable;
79 | if (!ReferenceEquals(asDisposable, null))
80 | {
81 | asDisposable.Dispose();
82 | }
83 | field.SetValue(this, null);
84 | }
85 | }
86 | }
87 | }
88 | }
89 | }
90 | }
91 |
--------------------------------------------------------------------------------
/Microsoft.HBase.Client.Tests/Utilities/EnumerableExtensions.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation
2 | // All rights reserved.
3 | //
4 | // Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 | // use this file except in compliance with the License. You may obtain a copy
6 | // of the License at http://www.apache.org/licenses/LICENSE-2.0
7 | //
8 | // THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
9 | // KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
10 | // WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
11 | // MERCHANTABLITY OR NON-INFRINGEMENT.
12 | //
13 | // See the Apache Version 2.0 License for specific language governing
14 | // permissions and limitations under the License.
15 |
16 | namespace Microsoft.HBase.Client.Tests.Utilities
17 | {
18 | using System;
19 | using System.Collections;
20 | using System.Collections.Generic;
21 | using System.Linq;
22 |
23 | internal static class EnumerableExtensions
24 | {
25 | ///Finds the index of the first item matching an expression in an enumerable.
26 | ///The enumerable to search.
27 | ///The expression to test the items against.
28 | ///The index of the first matching item, or -1 if no items match.
29 | internal static int FindIndex(this IEnumerable items, Func predicate)
30 | {
31 | if (items == null)
32 | {
33 | throw new ArgumentNullException("items");
34 | }
35 | if (predicate == null)
36 | {
37 | throw new ArgumentNullException("predicate");
38 | }
39 |
40 | int retVal = 0;
41 | foreach (T item in items)
42 | {
43 | if (predicate(item))
44 | {
45 | return retVal;
46 | }
47 | retVal++;
48 | }
49 | return -1;
50 | }
51 |
52 | internal static bool IsEmpty(this IEnumerable thisValue)
53 | {
54 | return !(thisValue).IsNull() && !thisValue.Cast