Skip to content

Commit

Permalink
Add variants API
Browse files Browse the repository at this point in the history
This adds a method call to fetch the available build variants from
the server.

Affects AdoptOpenJDK/openjdk-api#45
Fix #1
  • Loading branch information
io7m committed Mar 6, 2018
1 parent d4f81e0 commit e6c3a13
Show file tree
Hide file tree
Showing 13 changed files with 393 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import com.io7m.adoptopenjdk.spi.AOAPIVersionProviderType;
import com.io7m.adoptopenjdk.spi.AOException;
import com.io7m.adoptopenjdk.spi.AORelease;
import com.io7m.adoptopenjdk.spi.AOVariant;

import java.util.List;
import java.util.Objects;
Expand Down Expand Up @@ -98,6 +99,13 @@ public int rateLimitRemaining()
return this.requests.rateLimitRemaining();
}

@Override
public List<AOVariant> variants()
throws AOException
{
return this.requests.variants();
}

@Override
public List<AORelease> releasesForVariant(final String variant)
throws AOException
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,17 @@ public interface AOAPIRequestsType

int rateLimitRemaining();

/**
* List the available build variants on the server.
*
* @return A list of variants
*
* @throws AOException On any and all errors
*/

List<AOVariant> variants()
throws AOException;

/**
* List the available releases on the server.
*
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* Copyright © 2018 Mark Raynsford <code@io7m.com> http://io7m.com
*
* Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
* SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
* IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/

package com.io7m.adoptopenjdk.spi;

import org.immutables.value.Value;

/**
* A build variant (such as {@code "openjdk8"}).
*/

@ImmutableStyleType
@Value.Immutable
public interface AOVariantType
{
/**
* @return A variant identifier such as {@code "openjdk8"}.
*/

@Value.Parameter
String name();

/**
* @return A humanly-readable description of the variant (such as {@code "OpenJDK 8 with Hotspot"})
*/

@Value.Parameter
String description();
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import com.io7m.adoptopenjdk.spi.AOException;
import com.io7m.adoptopenjdk.spi.AORelease;
import com.io7m.adoptopenjdk.spi.AOVariant;
import com.io7m.adoptopenjdk.v1.AOv1HTTPException;
import com.io7m.adoptopenjdk.v1.AOv1Requests;
import com.io7m.adoptopenjdk.v1.AOv1RequestsType;
Expand Down Expand Up @@ -60,4 +61,22 @@ public void testParseOpenJDK8Releases()
}
}
}

@Test
public void testParseVariants()
throws AOException
{
try {
final AOv1RequestsType requests = AOv1Requests.open();
final List<AOVariant> variants = requests.variants();
Assert.assertTrue(
"Must have at least one variant parsed",
variants.size() > 0);
} catch (final AOv1HTTPException e) {
if (e.statusCode() == 429) {
LOG.info("exceeded rate limit on server: ", e);
return;
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import com.io7m.adoptopenjdk.spi.AOException;
import com.io7m.adoptopenjdk.spi.AORelease;
import com.io7m.adoptopenjdk.spi.AOVariant;
import com.io7m.adoptopenjdk.tests.spi.AOReleasesTest;
import com.io7m.adoptopenjdk.v1.AOv1Requests;
import com.io7m.adoptopenjdk.v1.AOv1RequestsType;
Expand Down Expand Up @@ -132,4 +133,47 @@ public void testParseOpenJDK8ReleasesFiltered()

Assert.assertEquals(releases_0, releases_1);
}

@Test
public void testParseVariants()
throws AOException, IOException
{
final MockConnection connection_0 =
MockConnection.create(
Map.of("X-RateLimit-Remaining", "100",
"Retry-After", "3600"));

final MockConnection connection_1 =
MockConnection.createWithData(
Map.of("X-RateLimit-Remaining", "200",
"Retry-After", "3600"),
resource("variants.json"));

final MockConnections connections = new MockConnections();
connections.addConnection(connection_0);
connections.addConnection(connection_1);

final AOv1RequestsType requests = AOv1Requests.open(connections);
final List<AOVariant> variants = requests.variants();

Assert.assertEquals(200L, (long) requests.rateLimitRemaining());
Assert.assertEquals(0L, (long) connections.queue().size());
Assert.assertEquals(5L, (long) variants.size());

Assert.assertEquals(
AOVariant.of("openjdk8", "OpenJDK 8 with Hotspot"),
variants.get(0));
Assert.assertEquals(
AOVariant.of("openjdk8-openj9", "OpenJDK 8 with Eclipse OpenJ9"),
variants.get(1));
Assert.assertEquals(
AOVariant.of("openjdk9", "OpenJDK 9 with Hotspot"),
variants.get(2));
Assert.assertEquals(
AOVariant.of("openjdk9-openj9", "OpenJDK 9 with Eclipse OpenJ9"),
variants.get(3));
Assert.assertEquals(
AOVariant.of("openjdk10", "OpenJDK 10 with Hotspot"),
variants.get(4));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import com.io7m.adoptopenjdk.spi.AOParseException;
import com.io7m.adoptopenjdk.spi.AORelease;
import com.io7m.adoptopenjdk.spi.AOVariant;
import com.io7m.adoptopenjdk.tests.spi.AOReleasesTest;
import com.io7m.adoptopenjdk.v1.AOv1Parser;
import org.junit.Assert;
Expand Down Expand Up @@ -155,4 +156,58 @@ public void testOpenJDK8Releases_Bad5()
parser.parseReleases(URI.create("openjdk8.json"), stream);
}
}

@Test
public void testVariants()
throws Exception
{
final AOv1Parser parser = new AOv1Parser();

try (InputStream stream = resource("variants.json")) {
final List<AOVariant> variants =
parser.parseVariants(URI.create("variants.json"), stream);

Assert.assertEquals(5L, (long) variants.size());

Assert.assertEquals(
AOVariant.of("openjdk8", "OpenJDK 8 with Hotspot"),
variants.get(0));
Assert.assertEquals(
AOVariant.of("openjdk8-openj9", "OpenJDK 8 with Eclipse OpenJ9"),
variants.get(1));
Assert.assertEquals(
AOVariant.of("openjdk9", "OpenJDK 9 with Hotspot"),
variants.get(2));
Assert.assertEquals(
AOVariant.of("openjdk9-openj9", "OpenJDK 9 with Eclipse OpenJ9"),
variants.get(3));
Assert.assertEquals(
AOVariant.of("openjdk10", "OpenJDK 10 with Hotspot"),
variants.get(4));
}
}

@Test
public void testVariants_Bad0()
throws Exception
{
final AOv1Parser parser = new AOv1Parser();

try (InputStream stream = resource("variants_bad_0.json")) {
this.expected.expect(AOParseException.class);
parser.parseVariants(URI.create("variants_bad_0.json"), stream);
}
}

@Test
public void testVariants_Bad1()
throws Exception
{
final AOv1Parser parser = new AOv1Parser();

try (InputStream stream = resource("variants_bad_1.json")) {
this.expected.expect(AOParseException.class);
parser.parseVariants(URI.create("variants_bad_1.json"), stream);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
[
{
"name": "OpenJDK 8 with Hotspot",
"variant": "openjdk8"
},
{
"name": "OpenJDK 8 with Eclipse OpenJ9",
"variant": "openjdk8-openj9"
},
{
"name": "OpenJDK 9 with Hotspot",
"variant": "openjdk9"
},
{
"name": "OpenJDK 9 with Eclipse OpenJ9",
"variant": "openjdk9-openj9"
},
{
"name": "OpenJDK 10 with Hotspot",
"variant": "openjdk10"
}
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[
{
"name": "OpenJDK 8 with Hotspot"
},
{
"variant": "openjdk8-openj9"
}
]
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
[
{
"name": "OpenJDK 8 with Hotspot",
"extra": "ignore me",
"variant": "openjdk8"
},
{
"name": "OpenJDK 8 with Eclipse OpenJ9",
"variant": "openjdk8-openj9",
"extra": {

}
},
{
"extra": [
"123"
],
"name": "OpenJDK 9 with Hotspot",
"variant": "openjdk9"
},
{
"name": "OpenJDK 9 with Eclipse OpenJ9",
"variant": "openjdk9-openj9"
},
{
"name": "OpenJDK 10 with Hotspot",
"variant": "openjdk10"
}
]

0 comments on commit e6c3a13

Please sign in to comment.