Skip to content

Commit

Permalink
Add ignore for empty vendor list (#723)
Browse files Browse the repository at this point in the history
  • Loading branch information
DGarbar authored May 18, 2020
1 parent 3b6c9c9 commit 6088454
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,10 @@ protected Map<String, String> readFileSystemCache(FileSystem fileSystem, String
* Returns a map with vendor ID as a key and a set of purposes as a value for given vendor list version.
*/
public Future<Map<Integer, V>> forVersion(int version) {
if (version <= 0) {
return Future.failedFuture(String.format("Vendor list for version %s not valid.", version));
}

final Map<Integer, V> idToVendor = cache.get(version);
if (idToVendor != null) {
return Future.succeededFuture(idToVendor);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,20 @@ public void shouldSaveFileWithExpectedPathAndContentIfVendorListNotFound() throw

// In-memory cache related tests

@Test
public void shouldFailIfVendorListIsBelowOrZero() {
// given
givenHttpClientProducesException(new RuntimeException());

// when
final Future<?> result1 = vendorListService.forVersion(0);
final Future<?> result2 = vendorListService.forVersion(-2);

// then
assertThat(result1).isFailed().hasMessage("Vendor list for version 0 not valid.");
assertThat(result2).isFailed().hasMessage("Vendor list for version -2 not valid.");
}

@Test
public void shouldFailIfVendorListNotFound() {
// given
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ public void setUp() {

given(bidderCatalog.knownVendorIds()).willReturn(singleton(52));

vendorListService = new VendorListServiceV2(CACHE_DIR, "http://vendorlist/{VERSION}", 0, null, bidderCatalog, fileSystem, httpClient, jacksonMapper);
vendorListService = new VendorListServiceV2(CACHE_DIR, "http://vendorlist/{VERSION}", 0, null, bidderCatalog,
fileSystem, httpClient, jacksonMapper);
}

// Creation related tests
Expand All @@ -72,7 +73,9 @@ public void creationShouldFailsIfCannotCreateCacheDir() {
given(fileSystem.mkdirsBlocking(anyString())).willThrow(new RuntimeException("dir creation error"));

// then
assertThatThrownBy(() -> new VendorListServiceV2(CACHE_DIR, "http://vendorlist/%s", 0, null, bidderCatalog, fileSystem, httpClient, jacksonMapper))
assertThatThrownBy(
() -> new VendorListServiceV2(CACHE_DIR, "http://vendorlist/%s", 0, null, bidderCatalog, fileSystem,
httpClient, jacksonMapper))
.hasMessage("dir creation error");
}

Expand All @@ -82,7 +85,9 @@ public void creationShouldFailsIfCannotReadFiles() {
given(fileSystem.readDirBlocking(anyString())).willThrow(new RuntimeException("read error"));

// then
assertThatThrownBy(() -> new VendorListServiceV2(CACHE_DIR, "http://vendorlist/%s", 0, null, bidderCatalog, fileSystem, httpClient, jacksonMapper))
assertThatThrownBy(
() -> new VendorListServiceV2(CACHE_DIR, "http://vendorlist/%s", 0, null, bidderCatalog, fileSystem,
httpClient, jacksonMapper))
.isInstanceOf(RuntimeException.class)
.hasMessage("read error");
}
Expand All @@ -94,7 +99,9 @@ public void creationShouldFailsIfCannotReadAtLeastOneVendorListFile() {
given(fileSystem.readFileBlocking(anyString())).willThrow(new RuntimeException("read error"));

// then
assertThatThrownBy(() -> new VendorListServiceV2(CACHE_DIR, "http://vendorlist/%s", 0, null, bidderCatalog, fileSystem, httpClient, jacksonMapper))
assertThatThrownBy(
() -> new VendorListServiceV2(CACHE_DIR, "http://vendorlist/%s", 0, null, bidderCatalog, fileSystem,
httpClient, jacksonMapper))
.isInstanceOf(RuntimeException.class)
.hasMessage("read error");
}
Expand All @@ -106,7 +113,9 @@ public void creationShouldFailsIfAtLeastOneVendorListFileCannotBeParsed() {
given(fileSystem.readFileBlocking(anyString())).willReturn(Buffer.buffer("invalid"));

// then
assertThatThrownBy(() -> new VendorListServiceV2(CACHE_DIR, "http://vendorlist/%s", 0, null, bidderCatalog, fileSystem, httpClient, jacksonMapper))
assertThatThrownBy(
() -> new VendorListServiceV2(CACHE_DIR, "http://vendorlist/%s", 0, null, bidderCatalog, fileSystem,
httpClient, jacksonMapper))
.isInstanceOf(PreBidException.class)
.hasMessage("Cannot parse vendor list from: invalid");
}
Expand Down Expand Up @@ -253,6 +262,20 @@ public void shouldSaveFileWithExpectedPathAndContentIfVendorListNotFound() throw

// In-memory cache related tests

@Test
public void shouldFailIfVendorListIsBelowOrZero() {
// given
givenHttpClientProducesException(new RuntimeException());

// when
final Future<?> result1 = vendorListService.forVersion(0);
final Future<?> result2 = vendorListService.forVersion(-2);

// then
assertThat(result1).isFailed().hasMessage("Vendor list for version 0 not valid.");
assertThat(result2).isFailed().hasMessage("Vendor list for version -2 not valid.");
}

@Test
public void shouldFailIfVendorListNotFound() {
// given
Expand Down

0 comments on commit 6088454

Please sign in to comment.