Skip to content

Commit af7b038

Browse files
authored
Merge pull request #76 from shabtaisharon/ESCP-808
ESCP-807, ESCP-808 & ESCP-838
2 parents 131ca6b + debcac3 commit af7b038

File tree

20 files changed

+516
-37
lines changed

20 files changed

+516
-37
lines changed

SpectraLogic.SpectraRioBrokerClient.Integration.Test/SpectraRioBrokerClientErrorTests.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,7 @@ public void CreateTokenErrorTests()
337337
Assert.ThrowsAsync<MissingAuthorizationHeaderException>(() => Task.FromResult(noAuthClient.GetBroker(new GetBrokerRequest(""))));
338338
Assert.ThrowsAsync<MissingAuthorizationHeaderException>(() => Task.FromResult(noAuthClient.GetDevice(new GetDeviceRequest(""))));
339339
Assert.ThrowsAsync<MissingAuthorizationHeaderException>(() => Task.FromResult(noAuthClient.GetJob(new GetJobRequest(Guid.Empty))));
340+
Assert.ThrowsAsync<MissingAuthorizationHeaderException>(() => Task.FromResult(noAuthClient.GetJobs(new GetJobsRequest())));
340341
Assert.ThrowsAsync<MissingAuthorizationHeaderException>(() => Task.FromResult(noAuthClient.Restore(new RestoreRequest("", Enumerable.Empty<RestoreFile>()))));
341342
Assert.ThrowsAsync<MissingAuthorizationHeaderException>(() => Task.FromResult(noAuthClient.Retry(new RetryRequest(Guid.Empty))));
342343

@@ -465,6 +466,12 @@ public void HeadDeviceErrorTests()
465466
Assert.IsFalse(SpectraRioBrokerClientFixture.SpectraRioBrokerClient.DoesDeviceExist("not_found"));
466467
}
467468

469+
[Test]
470+
public void HeadJobErrorTests()
471+
{
472+
Assert.IsFalse(SpectraRioBrokerClientFixture.SpectraRioBrokerClient.DoesJobExist(new Guid()));
473+
}
474+
468475
[Test]
469476
public void HttpErrorTests()
470477
{
@@ -568,6 +575,13 @@ public void NodeIsNotAClusterMemeberErrorTests()
568575
return Task.FromResult(SpectraRioBrokerClientFixture.SpectraRioBrokerClient.GetJob(request));
569576
});
570577

578+
Assert.ThrowsAsync<NodeIsNotAClusterMemeberException>(
579+
() =>
580+
{
581+
var request = new GetJobsRequest();
582+
return Task.FromResult(SpectraRioBrokerClientFixture.SpectraRioBrokerClient.GetJobs(request));
583+
});
584+
571585
Assert.ThrowsAsync<NodeIsNotAClusterMemeberException>(
572586
() =>
573587
{

SpectraLogic.SpectraRioBrokerClient.Integration.Test/SpectraRioBrokerClientIntegrationTests.cs

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -432,6 +432,46 @@ public void DoesBrokerObjectExistTest()
432432
}
433433
}
434434

435+
[Test]
436+
public void DoesJobExistTest()
437+
{
438+
var fileName1 = Guid.NewGuid().ToString();
439+
440+
try
441+
{
442+
SpectraRioBrokerClientFixture.SetupTestData();
443+
444+
var archiveRequest = new ArchiveRequest(SpectraRioBrokerClientFixture.BrokerName, new List<ArchiveFile>
445+
{
446+
new ArchiveFile(fileName1, $"{SpectraRioBrokerClientFixture.ArchiveTempDir}/F1.txt".ToFileUri(), 14, new Dictionary<string, string>{ { "fileName", fileName1 } }, false, false),
447+
});
448+
449+
var archiveJob = SpectraRioBrokerClientFixture.SpectraRioBrokerClient.Archive(archiveRequest);
450+
451+
var pollingAttemps = 0;
452+
do
453+
{
454+
archiveJob = SpectraRioBrokerClientFixture.SpectraRioBrokerClient.GetJob(
455+
new GetJobRequest(archiveJob.JobId));
456+
_log.Debug(archiveJob.Status);
457+
Thread.Sleep(TimeSpan.FromSeconds(POLLING_INTERVAL));
458+
pollingAttemps++;
459+
} while (archiveJob.Status.Status == JobStatusEnum.ACTIVE && pollingAttemps < MAX_POLLING_ATTEMPS);
460+
461+
Assert.Less(pollingAttemps, MAX_POLLING_ATTEMPS);
462+
Assert.AreEqual(JobStatusEnum.COMPLETED, archiveJob.Status.Status);
463+
464+
Assert.IsTrue(SpectraRioBrokerClientFixture.SpectraRioBrokerClient.DoesJobExist(archiveJob.JobId));
465+
}
466+
finally
467+
{
468+
var deleteF1Request = new DeleteFileRequest(SpectraRioBrokerClientFixture.BrokerName, fileName1);
469+
SpectraRioBrokerClientFixture.SpectraRioBrokerClient.DeleteFile(deleteF1Request);
470+
471+
Directory.Delete(SpectraRioBrokerClientFixture.ArchiveTempDir, true);
472+
}
473+
}
474+
435475
[Test]
436476
public void GetBrokerObjectsTest()
437477
{
@@ -590,6 +630,51 @@ public void GetBrokersTest()
590630
Assert.AreEqual(2, brokers.BrokerList.Count());
591631
}
592632

633+
[Test]
634+
public void GetJobsTest()
635+
{
636+
var fileName1 = Guid.NewGuid().ToString();
637+
try
638+
{
639+
var archiveJobsBefore = SpectraRioBrokerClientFixture.SpectraRioBrokerClient.GetJobs(new GetJobsRequest(jobType: JobTypeEnum.ARCHIVE.ToString(), jobStatus: JobStatusEnum.COMPLETED.ToString())).JobsList.Count();
640+
var restoreJobsBefore = SpectraRioBrokerClientFixture.SpectraRioBrokerClient.GetJobs(new GetJobsRequest(jobType: JobTypeEnum.RESTORE.ToString())).JobsList.Count();
641+
642+
SpectraRioBrokerClientFixture.SetupTestData();
643+
var archiveRequest = new ArchiveRequest(SpectraRioBrokerClientFixture.BrokerName, new List<ArchiveFile>
644+
{
645+
new ArchiveFile(fileName1, $"{SpectraRioBrokerClientFixture.ArchiveTempDir}/F1.txt".ToFileUri(), 14, new Dictionary<string, string>{ { "fileName", fileName1 } }, false, false),
646+
});
647+
648+
var archiveJob = SpectraRioBrokerClientFixture.SpectraRioBrokerClient.Archive(archiveRequest);
649+
650+
var pollingAttemps = 0;
651+
do
652+
{
653+
archiveJob = SpectraRioBrokerClientFixture.SpectraRioBrokerClient.GetJob(
654+
new GetJobRequest(archiveJob.JobId));
655+
_log.Debug(archiveJob.Status);
656+
Thread.Sleep(TimeSpan.FromSeconds(POLLING_INTERVAL));
657+
pollingAttemps++;
658+
} while (archiveJob.Status.Status == JobStatusEnum.ACTIVE && pollingAttemps < MAX_POLLING_ATTEMPS);
659+
660+
Assert.Less(pollingAttemps, MAX_POLLING_ATTEMPS);
661+
Assert.AreEqual(JobStatusEnum.COMPLETED, archiveJob.Status.Status);
662+
663+
var jobs = SpectraRioBrokerClientFixture.SpectraRioBrokerClient.GetJobs(new GetJobsRequest(jobType: JobTypeEnum.ARCHIVE.ToString(), jobStatus: JobStatusEnum.COMPLETED.ToString()));
664+
Assert.AreEqual(archiveJobsBefore + 1, jobs.JobsList.Count());
665+
666+
jobs = SpectraRioBrokerClientFixture.SpectraRioBrokerClient.GetJobs(new GetJobsRequest(jobType: JobTypeEnum.RESTORE.ToString()));
667+
Assert.AreEqual(restoreJobsBefore, jobs.JobsList.Count());
668+
}
669+
finally
670+
{
671+
var deleteF1Request = new DeleteFileRequest(SpectraRioBrokerClientFixture.BrokerName, fileName1);
672+
SpectraRioBrokerClientFixture.SpectraRioBrokerClient.DeleteFile(deleteF1Request);
673+
674+
Directory.Delete(SpectraRioBrokerClientFixture.ArchiveTempDir, true);
675+
}
676+
}
677+
593678
[Test]
594679
public void GetSystemTest()
595680
{

SpectraLogic.SpectraRioBrokerClient.Test/SpectraLogic.SpectraRioBrokerClient.Test.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@
9595
<EmbeddedResource Include="TestFiles\GetBrokerObjectResponse" />
9696
<EmbeddedResource Include="TestFiles\GetBrokerObjectsResponse" />
9797
<EmbeddedResource Include="TestFiles\GetBrokersResponse" />
98+
<EmbeddedResource Include="TestFiles\GetJobsResponse" />
9899
</ItemGroup>
99100
<ItemGroup>
100101
<ProjectReference Include="..\SpectraLogic.SpectraRioBrokerClient\SpectraLogic.SpectraRioBrokerClient.csproj">

SpectraLogic.SpectraRioBrokerClient.Test/SpectraRioBrokerClientTest.cs

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -397,6 +397,7 @@ public void GetBrokerTest()
397397
var broker = client.GetBroker(getBrokerRequest);
398398
Assert.AreEqual("brokerName", broker.BrokerName);
399399
Assert.AreEqual("2018-01-24T19:10:22.819Z[UTC]", broker.CreationDate);
400+
Assert.AreEqual(10, broker.ObjectCount);
400401

401402
mockBuilder.VerifyAll();
402403
mockNetwork.VerifyAll();
@@ -456,6 +457,33 @@ public void GetDeviceTest()
456457
mockNetwork.VerifyAll();
457458
}
458459

460+
[Test]
461+
public void GetJobsTest()
462+
{
463+
var getJobsRequest = new GetJobsRequest();
464+
465+
var mockNetwork = new Mock<INetwork>(MockBehavior.Strict);
466+
mockNetwork
467+
.Setup(n => n.Invoke(getJobsRequest))
468+
.Returns(new MockHttpWebResponse(
469+
"SpectraLogic.SpectraRioBrokerClient.Test.TestFiles.GetJobsResponse",
470+
HttpStatusCode.OK, null));
471+
472+
var mockBuilder = new Mock<ISpectraRioBrokerClientBuilder>(MockBehavior.Strict);
473+
mockBuilder
474+
.Setup(b => b.Build())
475+
.Returns(new SpectraRioBrokerClient(mockNetwork.Object));
476+
477+
var builder = mockBuilder.Object;
478+
var client = builder.Build();
479+
480+
var jobs = client.GetJobs(getJobsRequest);
481+
Assert.AreEqual(2, jobs.JobsList.Count());
482+
483+
mockBuilder.VerifyAll();
484+
mockNetwork.VerifyAll();
485+
}
486+
459487
[Test]
460488
public void GetJobWithStatusStringTest()
461489
{
@@ -638,6 +666,32 @@ public void HeadDeviceTest()
638666
mockNetwork.VerifyAll();
639667
}
640668

669+
[Test]
670+
public void HeadJobTest()
671+
{
672+
var headJobRequest = new HeadJobRequest(new Guid());
673+
674+
var mockNetwork = new Mock<INetwork>(MockBehavior.Strict);
675+
mockNetwork
676+
.SetupSequence(n => n.Invoke(It.IsAny<HeadJobRequest>()))
677+
.Returns(new MockHttpWebResponse(null, HttpStatusCode.OK, null))
678+
.Returns(new MockHttpWebResponse(null, HttpStatusCode.NotFound, null));
679+
680+
var mockBuilder = new Mock<ISpectraRioBrokerClientBuilder>(MockBehavior.Strict);
681+
mockBuilder
682+
.Setup(b => b.Build())
683+
.Returns(new SpectraRioBrokerClient(mockNetwork.Object));
684+
685+
var builder = mockBuilder.Object;
686+
var client = builder.Build();
687+
688+
Assert.IsTrue(client.DoesJobExist(new Guid()));
689+
Assert.IsFalse(client.DoesJobExist(new Guid()));
690+
691+
mockBuilder.VerifyAll();
692+
mockNetwork.VerifyAll();
693+
}
694+
641695
[Test]
642696
public void RestoreTest()
643697
{
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{
22
"name": "brokerName",
3-
"creationDate": "2018-01-24T19:10:22.819Z[UTC]"
3+
"creationDate": "2018-01-24T19:10:22.819Z[UTC]",
4+
"objectCount": 10
45
}

SpectraLogic.SpectraRioBrokerClient.Test/TestFiles/GetBrokersResponse

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,13 @@
22
"brokers": [
33
{
44
"name": "brokerName",
5-
"creationDate": "2018-01-24T19:10:22.819Z[UTC]"
5+
"creationDate": "2018-01-24T19:10:22.819Z[UTC]",
6+
"objectCount": 10
67
},
78
{
89
"name": "brokerName2",
9-
"creationDate": "2018-01-24T19:10:23.819Z[UTC]"
10+
"creationDate": "2018-01-24T19:10:23.819Z[UTC]",
11+
"objectCount": 20
1012
}
1113
]
1214
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
{
2+
"jobs": [
3+
{
4+
"id": "173e8530-5805-4a1c-a57b-969331e49683",
5+
"creationDate": "2018-12-17T22:00:34.625Z[UTC]",
6+
"lastUpdated": "2018-12-17T22:00:45.31Z[UTC]",
7+
"status": {
8+
"message": "",
9+
"status": "COMPLETED"
10+
},
11+
"jobType": "ARCHIVE",
12+
"numberOfFiles": 1,
13+
"filesTransferred": 1,
14+
"totalSizeInBytes": 14,
15+
"bytesTransferred": 14,
16+
"progress": 1
17+
},
18+
{
19+
"id": "173e8530-5805-4a1c-a57b-969331e49683",
20+
"creationDate": "2018-12-17T22:00:34.625Z[UTC]",
21+
"lastUpdated": "2018-12-17T22:00:45.31Z[UTC]",
22+
"status": {
23+
"message": "",
24+
"status": "COMPLETED"
25+
},
26+
"jobType": "RESTORE",
27+
"numberOfFiles": 1,
28+
"filesTransferred": 1,
29+
"totalSizeInBytes": 14,
30+
"bytesTransferred": 14,
31+
"progress": 1
32+
}
33+
]
34+
}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/*
2+
* ******************************************************************************
3+
* Copyright 2014-2018 Spectra Logic Corporation. All Rights Reserved.
4+
* Licensed under the Apache License, Version 2.0 (the "License"). You may not use
5+
* this file except in compliance with the License. A copy of the License is located at
6+
*
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* or in the "license" file accompanying this file.
10+
* This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
11+
* CONDITIONS OF ANY KIND, either express or implied. See the License for the
12+
* specific language governing permissions and limitations under the License.
13+
* ****************************************************************************
14+
*/
15+
16+
using SpectraLogic.SpectraRioBrokerClient.Model;
17+
18+
namespace SpectraLogic.SpectraRioBrokerClient.Calls
19+
{
20+
/// <summary>
21+
///
22+
/// </summary>
23+
/// <seealso cref="SpectraLogic.SpectraRioBrokerClient.Calls.RestRequest" />
24+
public class GetJobsRequest : RestRequest
25+
{
26+
#region Public Constructors
27+
28+
/// <summary>Initializes a new instance of the <see cref="GetJobsRequest"/> class.</summary>
29+
/// <param name="broker">The broker.</param>
30+
/// <param name="jobType">Type of the job.</param>
31+
/// <param name="jobStatus">The job status.</param>
32+
public GetJobsRequest(string broker = null, string jobType = null, string jobStatus = null)
33+
{
34+
if (broker != null)
35+
{
36+
QueryParams.Add("broker", broker);
37+
}
38+
39+
if (jobType != null)
40+
{
41+
QueryParams.Add("job_type", jobType);
42+
}
43+
44+
if (broker != null)
45+
{
46+
QueryParams.Add("status", jobStatus);
47+
}
48+
}
49+
50+
#endregion Public Constructors
51+
52+
#region Internal Properties
53+
54+
internal override string Path => $"api/jobs";
55+
internal override HttpVerb Verb => HttpVerb.GET;
56+
57+
#endregion Internal Properties
58+
}
59+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/*
2+
* ******************************************************************************
3+
* Copyright 2014-2018 Spectra Logic Corporation. All Rights Reserved.
4+
* Licensed under the Apache License, Version 2.0 (the "License"). You may not use
5+
* this file except in compliance with the License. A copy of the License is located at
6+
*
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* or in the "license" file accompanying this file.
10+
* This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
11+
* CONDITIONS OF ANY KIND, either express or implied. See the License for the
12+
* specific language governing permissions and limitations under the License.
13+
* ****************************************************************************
14+
*/
15+
16+
using System;
17+
18+
namespace SpectraLogic.SpectraRioBrokerClient.Calls
19+
{
20+
internal class HeadJobRequest : RestRequest
21+
{
22+
#region Private Fields
23+
24+
private Guid JobId;
25+
26+
#endregion Private Fields
27+
28+
#region Public Constructors
29+
30+
public HeadJobRequest(Guid jobId)
31+
{
32+
JobId = jobId;
33+
}
34+
35+
#endregion Public Constructors
36+
37+
#region Internal Properties
38+
39+
internal override string Path => $"/api/jobs/{JobId}";
40+
internal override HttpVerb Verb => HttpVerb.HEAD;
41+
42+
#endregion Internal Properties
43+
}
44+
}

0 commit comments

Comments
 (0)