From 1ef2c93ec134234e72abe254b1675bf4236f2300 Mon Sep 17 00:00:00 2001 From: Adrian Cole Date: Tue, 14 Oct 2014 08:04:36 -0700 Subject: [PATCH] Only read hpack tests for the current draft. --- .../spdy/HpackDecodeInteropGoodTest.java | 59 ------------------- ...dTest.java => HpackDecodeInteropTest.java} | 22 ++----- .../spdy/hpackjson/HpackJsonUtil.java | 31 ++++++++-- .../okhttp/internal/spdy/hpackjson/Story.java | 5 ++ 4 files changed, 37 insertions(+), 80 deletions(-) delete mode 100644 okhttp-hpacktests/src/test/java/com/squareup/okhttp/internal/spdy/HpackDecodeInteropGoodTest.java rename okhttp-hpacktests/src/test/java/com/squareup/okhttp/internal/spdy/{HpackDecodeInteropBadTest.java => HpackDecodeInteropTest.java} (69%) diff --git a/okhttp-hpacktests/src/test/java/com/squareup/okhttp/internal/spdy/HpackDecodeInteropGoodTest.java b/okhttp-hpacktests/src/test/java/com/squareup/okhttp/internal/spdy/HpackDecodeInteropGoodTest.java deleted file mode 100644 index 55852b8b5..000000000 --- a/okhttp-hpacktests/src/test/java/com/squareup/okhttp/internal/spdy/HpackDecodeInteropGoodTest.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Copyright (C) 2014 Square, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.squareup.okhttp.internal.spdy; - -import com.squareup.okhttp.internal.spdy.hpackjson.Story; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; - -import java.util.Collection; - -/** - * Known good tests for HPACK interop. - */ -@RunWith(Parameterized.class) -public class HpackDecodeInteropGoodTest extends HpackDecodeTestBase { - - // TODO: Filter on the json key for draft, which explains some of the failures. - private static final String[] GOOD_INTEROP_TESTS = { - "go-hpack", - "haskell-http2-linear", - "haskell-http2-linear-huffman", - "haskell-http2-naive", - "haskell-http2-naive-huffman", - "haskell-http2-static", - "haskell-http2-static-huffman", - "nghttp2", - "nghttp2-16384-4096", - "nghttp2-change-table-size", - "node-http2-hpack", - }; - - public HpackDecodeInteropGoodTest(Story story) { - super(story); - } - - @Parameterized.Parameters(name="{0}") - public static Collection createStories() throws Exception { - return createStories(GOOD_INTEROP_TESTS); - } - - @Test - public void testGoodDecoderInterop() throws Exception { - testDecoder(); - } -} diff --git a/okhttp-hpacktests/src/test/java/com/squareup/okhttp/internal/spdy/HpackDecodeInteropBadTest.java b/okhttp-hpacktests/src/test/java/com/squareup/okhttp/internal/spdy/HpackDecodeInteropTest.java similarity index 69% rename from okhttp-hpacktests/src/test/java/com/squareup/okhttp/internal/spdy/HpackDecodeInteropBadTest.java rename to okhttp-hpacktests/src/test/java/com/squareup/okhttp/internal/spdy/HpackDecodeInteropTest.java index 3e4850688..30e1a7b47 100644 --- a/okhttp-hpacktests/src/test/java/com/squareup/okhttp/internal/spdy/HpackDecodeInteropBadTest.java +++ b/okhttp-hpacktests/src/test/java/com/squareup/okhttp/internal/spdy/HpackDecodeInteropTest.java @@ -16,35 +16,23 @@ package com.squareup.okhttp.internal.spdy; import com.squareup.okhttp.internal.spdy.hpackjson.Story; -import org.junit.Ignore; +import java.util.Collection; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.Parameterized; -import java.util.Collection; +import static com.squareup.okhttp.internal.spdy.hpackjson.HpackJsonUtil.storiesForCurrentDraft; -/** - * Known bad tests for HPACK interop. - */ -// TODO: fix these tests (see if the input/test is legit, fix the implementation.) -@Ignore @RunWith(Parameterized.class) -public class HpackDecodeInteropBadTest extends HpackDecodeTestBase { +public class HpackDecodeInteropTest extends HpackDecodeTestBase { - private static final String[] BAD_INTEROP_TESTS = { - "hyper-hpack", - "node-http2-protocol", - "raw-data", - "twitter-hpack" - }; - - public HpackDecodeInteropBadTest(Story story) { + public HpackDecodeInteropTest(Story story) { super(story); } @Parameterized.Parameters(name="{0}") public static Collection createStories() throws Exception { - return createStories(BAD_INTEROP_TESTS); + return createStories(storiesForCurrentDraft()); } @Test diff --git a/okhttp-hpacktests/src/test/java/com/squareup/okhttp/internal/spdy/hpackjson/HpackJsonUtil.java b/okhttp-hpacktests/src/test/java/com/squareup/okhttp/internal/spdy/hpackjson/HpackJsonUtil.java index d0695446d..9d721abc9 100644 --- a/okhttp-hpacktests/src/test/java/com/squareup/okhttp/internal/spdy/hpackjson/HpackJsonUtil.java +++ b/okhttp-hpacktests/src/test/java/com/squareup/okhttp/internal/spdy/hpackjson/HpackJsonUtil.java @@ -17,26 +17,49 @@ package com.squareup.okhttp.internal.spdy.hpackjson; import com.google.gson.Gson; import com.google.gson.GsonBuilder; - +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; +import java.net.URISyntaxException; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; /** * Utilities for reading HPACK tests. */ public final class HpackJsonUtil { + private static final int CURRENT_DRAFT = 9; - private static final String STORY_RESOURCE_FORMAT = - "/hpack-test-case/%s/story_%02d.json"; + private static final String STORY_RESOURCE_FORMAT = "/hpack-test-case/%s/story_%02d.json"; private static final Gson GSON = new GsonBuilder().create(); - private static Story readStory(InputStream jsonResource) throws Exception { + private static Story readStory(InputStream jsonResource) throws IOException { return GSON.fromJson(new InputStreamReader(jsonResource, "UTF-8"), Story.class); } + /** Iterate through the hpack-test-case resources, only picking stories for the current draft. */ + public static String[] storiesForCurrentDraft() throws URISyntaxException { + File testCaseDirectory = new File(HpackJsonUtil.class.getResource("/hpack-test-case").toURI()); + List storyNames = new ArrayList(); + for (File path : testCaseDirectory.listFiles()) { + if (path.isDirectory() && Arrays.asList(path.list()).contains("story_00.json")) { + try { + Story firstStory = readStory(new FileInputStream(new File(path, "story_00.json"))); + if (firstStory.getDraft() == CURRENT_DRAFT) { + storyNames.add(path.getName()); + } + } catch (IOException ignored) { + // Skip this path. + } + } + } + return storyNames.toArray(new String[storyNames.size()]); + } + /** * Reads stories named "story_xx.json" from the folder provided. */ diff --git a/okhttp-hpacktests/src/test/java/com/squareup/okhttp/internal/spdy/hpackjson/Story.java b/okhttp-hpacktests/src/test/java/com/squareup/okhttp/internal/spdy/hpackjson/Story.java index e7898cb82..5ff2b0767 100644 --- a/okhttp-hpacktests/src/test/java/com/squareup/okhttp/internal/spdy/hpackjson/Story.java +++ b/okhttp-hpacktests/src/test/java/com/squareup/okhttp/internal/spdy/hpackjson/Story.java @@ -40,6 +40,11 @@ public class Story implements Cloneable { return cases; } + /** We only expect stories that match the draft we've implemented to pass. */ + public int getDraft() { + return draft; + } + @Override public Story clone() throws CloneNotSupportedException { Story story = new Story();