You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mina.apache.org by je...@apache.org on 2015/04/12 23:52:37 UTC

[4/8] mina git commit: Complete low level HTTP2

http://git-wip-us.apache.org/repos/asf/mina/blob/8ca3d89d/http2/src/test/java/org/apache/mina/http2/impl/BytePartialDecoderTest.java
----------------------------------------------------------------------
diff --git a/http2/src/test/java/org/apache/mina/http2/impl/BytePartialDecoderTest.java b/http2/src/test/java/org/apache/mina/http2/impl/BytePartialDecoderTest.java
new file mode 100644
index 0000000..6a30567
--- /dev/null
+++ b/http2/src/test/java/org/apache/mina/http2/impl/BytePartialDecoderTest.java
@@ -0,0 +1,75 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you 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 org.apache.mina.http2.impl;
+
+import static org.junit.Assert.assertArrayEquals;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import java.nio.ByteBuffer;
+
+import org.apache.mina.http2.impl.BytePartialDecoder;
+import org.junit.Test;
+
+/**
+ * 
+ * @author <a href="http://mina.apache.org">Apache MINA Project</a>
+ */
+public class BytePartialDecoderTest {
+
+    private static final byte[] SAMPLE_VALUE_1 = new byte[] {0x74, 0x18, 0x4F, 0x68};
+    private static final byte[] SAMPLE_VALUE_2 = new byte[] {0x74, 0x18, 0x4F, 0x68, 0x0F};
+
+    @Test
+    public void checkSimpleValue() {
+        BytePartialDecoder decoder = new BytePartialDecoder(4);
+        ByteBuffer buffer = ByteBuffer.wrap(SAMPLE_VALUE_1);
+        assertTrue(decoder.consume(buffer));
+        assertArrayEquals(SAMPLE_VALUE_1, decoder.getValue());
+    }
+    
+    @Test
+    public void checkNotenoughData() {
+        BytePartialDecoder decoder = new BytePartialDecoder(4);
+        ByteBuffer buffer = ByteBuffer.wrap(new byte[] {0x00, 0x00});
+        assertFalse(decoder.consume(buffer));
+    }
+
+    @Test
+    public void checkTooMuchData() {
+        BytePartialDecoder decoder = new BytePartialDecoder(4);
+        ByteBuffer buffer = ByteBuffer.wrap(SAMPLE_VALUE_2);
+        assertTrue(decoder.consume(buffer));
+        assertArrayEquals(SAMPLE_VALUE_1, decoder.getValue());
+        assertEquals(1, buffer.remaining());
+    }
+
+    @Test
+    public void checkDecodingIn2Steps() {
+        BytePartialDecoder decoder = new BytePartialDecoder(4);
+        ByteBuffer buffer = ByteBuffer.wrap(new byte[] {SAMPLE_VALUE_2[0], SAMPLE_VALUE_2[1]});
+        assertFalse(decoder.consume(buffer));
+        buffer = ByteBuffer.wrap(new byte[] {SAMPLE_VALUE_2[2], SAMPLE_VALUE_2[3], SAMPLE_VALUE_2[4]});
+        assertTrue(decoder.consume(buffer));
+        assertArrayEquals(SAMPLE_VALUE_1, decoder.getValue());
+        assertEquals(1, buffer.remaining());
+    }
+}

http://git-wip-us.apache.org/repos/asf/mina/blob/8ca3d89d/http2/src/test/java/org/apache/mina/http2/impl/Http2FrameHeaderPartialDecoderTest.java
----------------------------------------------------------------------
diff --git a/http2/src/test/java/org/apache/mina/http2/impl/Http2FrameHeaderPartialDecoderTest.java b/http2/src/test/java/org/apache/mina/http2/impl/Http2FrameHeaderPartialDecoderTest.java
new file mode 100644
index 0000000..dc12569
--- /dev/null
+++ b/http2/src/test/java/org/apache/mina/http2/impl/Http2FrameHeaderPartialDecoderTest.java
@@ -0,0 +1,87 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you 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 org.apache.mina.http2.impl;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+import java.nio.ByteBuffer;
+
+import org.apache.mina.http2.impl.Http2FrameHeadePartialDecoder;
+import org.apache.mina.http2.impl.Http2FrameHeadePartialDecoder.Http2FrameHeader;
+import org.junit.Test;
+
+/**
+ * 
+ * @author <a href="http://mina.apache.org">Apache MINA Project</a>
+ */
+public class Http2FrameHeaderPartialDecoderTest {
+
+    @Test
+    public void checkStandardValue() {
+        Http2FrameHeadePartialDecoder decoder = new Http2FrameHeadePartialDecoder();
+        ByteBuffer buffer = ByteBuffer.wrap(new byte[] {0x00, 0x00, 0x00, /*length*/
+                                                        0x00, /*type*/
+                                                        0x00, /*flags*/
+                                                        0x00, 0x00, 0x00, 0x01 /*streamID*/});
+        assertTrue(decoder.consume(buffer));
+        Http2FrameHeader header = decoder.getValue();
+        assertNotNull(header);
+        assertEquals(0, header.getLength());
+        assertEquals(0, header.getType());
+        assertEquals(0, header.getFlags());
+        assertEquals(1, header.getStreamID());
+    }
+
+    @Test
+    public void checkReservedBitIsNotTransmitted() {
+        Http2FrameHeadePartialDecoder decoder = new Http2FrameHeadePartialDecoder();
+        ByteBuffer buffer = ByteBuffer.wrap(new byte[] {0x00, 0x00, 0x00, /*length*/
+                                                        0x00, /*type*/
+                                                        0x00, /*flags*/
+                                                        (byte)0x80, 0x00, 0x00, 0x01 /*streamID*/});
+        assertTrue(decoder.consume(buffer));
+        Http2FrameHeader header = decoder.getValue();
+        assertNotNull(header);
+        assertEquals(0, header.getLength());
+        assertEquals(0, header.getType());
+        assertEquals(0, header.getFlags());
+        assertEquals(1, header.getStreamID());
+    }
+    
+    @Test
+    public void checkPayLoadIsTransmitted() {
+        Http2FrameHeadePartialDecoder decoder = new Http2FrameHeadePartialDecoder();
+        ByteBuffer buffer = ByteBuffer.wrap(new byte[] {0x00, 0x00, 0x01, /*length*/
+                                                        0x00, /*type*/
+                                                        0x00, /*flags*/
+                                                        (byte)0x80, 0x00, 0x00, 0x01, /*streamID*/
+                                                        0x40});
+        assertTrue(decoder.consume(buffer));
+        Http2FrameHeader header = decoder.getValue();
+        assertNotNull(header);
+        assertEquals(1, header.getLength());
+        assertEquals(0, header.getType());
+        assertEquals(0, header.getFlags());
+        assertEquals(1, header.getStreamID());
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/mina/blob/8ca3d89d/http2/src/test/java/org/apache/mina/http2/impl/IntPartialDecoderTest.java
----------------------------------------------------------------------
diff --git a/http2/src/test/java/org/apache/mina/http2/impl/IntPartialDecoderTest.java b/http2/src/test/java/org/apache/mina/http2/impl/IntPartialDecoderTest.java
new file mode 100644
index 0000000..674a76e
--- /dev/null
+++ b/http2/src/test/java/org/apache/mina/http2/impl/IntPartialDecoderTest.java
@@ -0,0 +1,71 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you 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 org.apache.mina.http2.impl;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import java.nio.ByteBuffer;
+
+import org.apache.mina.http2.impl.IntPartialDecoder;
+import org.junit.Test;
+
+/**
+ * 
+ * @author <a href="http://mina.apache.org">Apache MINA Project</a>
+ */
+public class IntPartialDecoderTest {
+
+    @Test
+    public void checkSimpleValue() {
+        IntPartialDecoder decoder = new IntPartialDecoder();
+        ByteBuffer buffer = ByteBuffer.wrap(new byte[] {0x00, 0x00, 0x00, 0x00});
+        assertTrue(decoder.consume(buffer));
+        assertEquals(0, decoder.getValue().intValue());
+    }
+    
+    @Test
+    public void checkNotenoughData() {
+        IntPartialDecoder decoder = new IntPartialDecoder();
+        ByteBuffer buffer = ByteBuffer.wrap(new byte[] {0x00, 0x00});
+        assertFalse(decoder.consume(buffer));
+    }
+
+    @Test
+    public void checkTooMuchData() {
+        IntPartialDecoder decoder = new IntPartialDecoder();
+        ByteBuffer buffer = ByteBuffer.wrap(new byte[] {0x00, 0x00, 0x00, 0x00, 0x00});
+        assertTrue(decoder.consume(buffer));
+        assertEquals(0, decoder.getValue().intValue());
+        assertEquals(1, buffer.remaining());
+    }
+
+    @Test
+    public void checkDecodingIn2Steps() {
+        IntPartialDecoder decoder = new IntPartialDecoder();
+        ByteBuffer buffer = ByteBuffer.wrap(new byte[] {0x00, 0x00});
+        assertFalse(decoder.consume(buffer));
+        buffer = ByteBuffer.wrap(new byte[] {0x00, 0x00, 0x00});
+        assertTrue(decoder.consume(buffer));
+        assertEquals(0, decoder.getValue().intValue());
+        assertEquals(1, buffer.remaining());
+    }
+}

http://git-wip-us.apache.org/repos/asf/mina/blob/8ca3d89d/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
index 97a960e..cc851e7 100644
--- a/pom.xml
+++ b/pom.xml
@@ -111,6 +111,7 @@
     <module>core</module>
     <module>codec</module>
     <module>http</module>
+    <module>http2</module>
     <module>examples</module>
     <module>coap</module>
     <module>thrift</module>