diff options
author | johnme@chromium.org <johnme@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-07-18 11:25:15 +0000 |
---|---|---|
committer | johnme@chromium.org <johnme@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-07-18 11:25:15 +0000 |
commit | af34023e1938a3a8463c92667a9eee4880366812 (patch) | |
tree | b2f9b39855f78452a2a3e956ded16df663fe3915 /mojo/android/javatests | |
parent | 376fa417bc704694dd8fd8db559fd048a3f79a62 (diff) | |
download | chromium_src-af34023e1938a3a8463c92667a9eee4880366812.zip chromium_src-af34023e1938a3a8463c92667a9eee4880366812.tar.gz chromium_src-af34023e1938a3a8463c92667a9eee4880366812.tar.bz2 |
Revert of Adding a router class to handle messages that expect responses. (https://codereview.chromium.org/371603003/)
Reason for revert:
This appears to have broken mojotest_instrumentation_tests with the errors like the ones listed below.
http://build.chromium.org/p/chromium.webkit/builders/Android%20Tests%20%28dbg%29/builds/20270
C 52.086s Main [FAIL] org.chromium.mojo.bindings.ConnectorTest#testErrors:
C 52.086s Main java.lang.NoClassDefFoundError: java.util.Objects
C 52.086s Main at org.chromium.mojo.bindings.MessageHeader.equals(MessageHeader.java:189)
C 52.086s Main at org.chromium.mojo.bindings.MessageWithHeader.<init>(MessageWithHeader.java:29)
C 52.086s Main at org.chromium.mojo.bindings.MessageWithHeader.<init>(MessageWithHeader.java:39)
C 52.086s Main at org.chromium.mojo.bindings.BindingsTestUtils.newRandomMessageWithHeader(BindingsTestUtils.java:85)
C 52.086s Main at org.chromium.mojo.bindings.ConnectorTest.setUp(ConnectorTest.java:53)
C 52.086s Main at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:191)
C 52.086s Main at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:176)
C 52.086s Main at android.test.InstrumentationTestRunner.onStart(InstrumentationTestRunner.java:554)
C 52.086s Main at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:1701)
C 52.091s Main [CRASH] org.chromium.mojo.bindings.RouterTest#testReceivingViaRouterWithResponse:
C 52.091s Main Native crash: Segmentation fault
Original issue's description:
> Adding a router class to handle messages that expect responses.
>
> This also introduce the notion of message header to allow routing.
>
> R=rmcilroy@chromium.org
>
> Committed: https://src.chromium.org/viewvc/chrome?view=rev&revision=283767
TBR=qsr
NOTREECHECKS=true
NOTRY=true
Review URL: https://codereview.chromium.org/392223004
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@284059 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'mojo/android/javatests')
-rw-r--r-- | mojo/android/javatests/src/org/chromium/mojo/TestUtils.java | 2 | ||||
-rw-r--r-- | mojo/android/javatests/src/org/chromium/mojo/bindings/BindingsTestUtils.java | 51 | ||||
-rw-r--r-- | mojo/android/javatests/src/org/chromium/mojo/bindings/ConnectorTest.java | 15 | ||||
-rw-r--r-- | mojo/android/javatests/src/org/chromium/mojo/bindings/MessageHeaderTest.java | 69 | ||||
-rw-r--r-- | mojo/android/javatests/src/org/chromium/mojo/bindings/MessageTest.java (renamed from mojo/android/javatests/src/org/chromium/mojo/bindings/MessageWithHeaderTest.java) | 33 | ||||
-rw-r--r-- | mojo/android/javatests/src/org/chromium/mojo/bindings/RouterTest.java | 134 |
6 files changed, 32 insertions, 272 deletions
diff --git a/mojo/android/javatests/src/org/chromium/mojo/TestUtils.java b/mojo/android/javatests/src/org/chromium/mojo/TestUtils.java index 2134a9f..ad13ca9 100644 --- a/mojo/android/javatests/src/org/chromium/mojo/TestUtils.java +++ b/mojo/android/javatests/src/org/chromium/mojo/TestUtils.java @@ -5,7 +5,6 @@ package org.chromium.mojo; import java.nio.ByteBuffer; -import java.nio.ByteOrder; import java.util.Random; /** @@ -23,7 +22,6 @@ public final class TestUtils { RANDOM.setSeed(size); RANDOM.nextBytes(bytes); ByteBuffer data = ByteBuffer.allocateDirect(size); - data.order(ByteOrder.nativeOrder()); data.put(bytes); data.flip(); return data; diff --git a/mojo/android/javatests/src/org/chromium/mojo/bindings/BindingsTestUtils.java b/mojo/android/javatests/src/org/chromium/mojo/bindings/BindingsTestUtils.java index fa93d37..3fcee86 100644 --- a/mojo/android/javatests/src/org/chromium/mojo/bindings/BindingsTestUtils.java +++ b/mojo/android/javatests/src/org/chromium/mojo/bindings/BindingsTestUtils.java @@ -4,12 +4,8 @@ package org.chromium.mojo.bindings; -import org.chromium.mojo.TestUtils; -import org.chromium.mojo.system.Handle; import org.chromium.mojo.system.MojoException; -import org.chromium.mojo.system.Pair; -import java.nio.ByteBuffer; import java.util.ArrayList; import java.util.List; @@ -23,65 +19,32 @@ public class BindingsTestUtils { */ public static class RecordingMessageReceiver implements MessageReceiver { - public final List<MessageWithHeader> messages = new ArrayList<MessageWithHeader>(); + public final List<Message> messages = new ArrayList<Message>(); /** - * @see MessageReceiver#accept(MessageWithHeader) + * @see MessageReceiver#accept(Message) */ @Override - public boolean accept(MessageWithHeader message) { + public boolean accept(Message message) { messages.add(message); return true; } } /** - * {@link MessageReceiverWithResponder} that records any message it receives. + * {@link Connector.ErrorHandler} that records any error it received. */ - public static class RecordingMessageReceiverWithResponder extends RecordingMessageReceiver - implements MessageReceiverWithResponder { - - public final List<Pair<MessageWithHeader, MessageReceiver>> messagesWithReceivers = - new ArrayList<Pair<MessageWithHeader, MessageReceiver>>(); - - /** - * @see MessageReceiverWithResponder#acceptWithResponder(MessageWithHeader, - * MessageReceiver) - */ - @Override - public boolean acceptWithResponder(MessageWithHeader message, MessageReceiver responder) { - messagesWithReceivers.add(Pair.create(message, responder)); - return true; - } - } - - /** - * {@link ConnectionErrorHandler} that records any error it received. - */ - public static class CapturingErrorHandler implements ConnectionErrorHandler { + public static class CapturingErrorHandler implements Connector.ErrorHandler { public MojoException exception = null; /** - * @see ConnectionErrorHandler#onConnectionError(MojoException) + * @see Connector.ErrorHandler#onError(MojoException) */ @Override - public void onConnectionError(MojoException e) { + public void onError(MojoException e) { exception = e; } } - /** - * Creates a new valid {@link MessageWithHeader}. - */ - public static MessageWithHeader newRandomMessageWithHeader(int size) { - assert size > 16; - ByteBuffer message = TestUtils.newRandomBuffer(size); - int[] headerAsInts = { 16, 2, 0, 0 }; - for (int i = 0; i < 4; ++i) { - message.putInt(4 * i, headerAsInts[i]); - } - message.position(0); - return new MessageWithHeader(new Message(message, new ArrayList<Handle>())); - } } diff --git a/mojo/android/javatests/src/org/chromium/mojo/bindings/ConnectorTest.java b/mojo/android/javatests/src/org/chromium/mojo/bindings/ConnectorTest.java index ff5b464..21ac624 100644 --- a/mojo/android/javatests/src/org/chromium/mojo/bindings/ConnectorTest.java +++ b/mojo/android/javatests/src/org/chromium/mojo/bindings/ConnectorTest.java @@ -7,6 +7,7 @@ package org.chromium.mojo.bindings; import android.test.suitebuilder.annotation.SmallTest; import org.chromium.mojo.MojoTestCase; +import org.chromium.mojo.TestUtils; import org.chromium.mojo.bindings.BindingsTestUtils.CapturingErrorHandler; import org.chromium.mojo.bindings.BindingsTestUtils.RecordingMessageReceiver; import org.chromium.mojo.system.Core; @@ -30,7 +31,7 @@ public class ConnectorTest extends MojoTestCase { private MessagePipeHandle mHandle; private Connector mConnector; - private MessageWithHeader mTestMessage; + private Message mTestMessage; private RecordingMessageReceiver mReceiver; private CapturingErrorHandler mErrorHandler; @@ -50,7 +51,7 @@ public class ConnectorTest extends MojoTestCase { mErrorHandler = new CapturingErrorHandler(); mConnector.setErrorHandler(mErrorHandler); mConnector.start(); - mTestMessage = BindingsTestUtils.newRandomMessageWithHeader(DATA_LENGTH); + mTestMessage = new Message(TestUtils.newRandomBuffer(DATA_LENGTH), new ArrayList<Handle>()); assertNull(mErrorHandler.exception); assertEquals(0, mReceiver.messages.size()); } @@ -77,7 +78,7 @@ public class ConnectorTest extends MojoTestCase { MessagePipeHandle.ReadFlags.NONE); assertEquals(MojoResult.OK, result.getMojoResult()); assertEquals(DATA_LENGTH, result.getMessageSize()); - assertEquals(mTestMessage.getMessage().buffer, received); + assertEquals(mTestMessage.buffer, received); } /** @@ -85,14 +86,14 @@ public class ConnectorTest extends MojoTestCase { */ @SmallTest public void testReceivingMessage() { - mHandle.writeMessage(mTestMessage.getMessage().buffer, new ArrayList<Handle>(), + mHandle.writeMessage(mTestMessage.buffer, new ArrayList<Handle>(), MessagePipeHandle.WriteFlags.NONE); nativeRunLoop(RUN_LOOP_TIMEOUT_MS); assertNull(mErrorHandler.exception); assertEquals(1, mReceiver.messages.size()); - MessageWithHeader received = mReceiver.messages.get(0); - assertEquals(0, received.getMessage().handles.size()); - assertEquals(mTestMessage.getMessage().buffer, received.getMessage().buffer); + Message received = mReceiver.messages.get(0); + assertEquals(0, received.handles.size()); + assertEquals(mTestMessage.buffer, received.buffer); } /** diff --git a/mojo/android/javatests/src/org/chromium/mojo/bindings/MessageHeaderTest.java b/mojo/android/javatests/src/org/chromium/mojo/bindings/MessageHeaderTest.java deleted file mode 100644 index caf4b8b..0000000 --- a/mojo/android/javatests/src/org/chromium/mojo/bindings/MessageHeaderTest.java +++ /dev/null @@ -1,69 +0,0 @@ -// Copyright 2014 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -package org.chromium.mojo.bindings; - -import android.test.suitebuilder.annotation.SmallTest; - -import junit.framework.TestCase; - -import org.chromium.mojo.bindings.test.mojom.imported.Point; - -/** - * Testing internal classes of interfaces. - */ -public class MessageHeaderTest extends TestCase { - - /** - * Testing that headers are identical after being serialized/deserialized. - */ - @SmallTest - public void testSimpleMessageHeader() { - final int xValue = 1; - final int yValue = 2; - final int type = 6; - Point p = new Point(); - p.x = xValue; - p.y = yValue; - MessageWithHeader message = p.serializeWithHeader(null, new MessageHeader(type)); - - MessageHeader header = message.getHeader(); - assertTrue(header.validateHeader(type, 0)); - assertEquals(type, header.getType()); - assertEquals(0, header.getFlags()); - - Point p2 = Point.deserialize(message.getPayload()); - assertNotNull(p2); - assertEquals(p.x, p2.x); - assertEquals(p.y, p2.y); - } - - /** - * Testing that headers are identical after being serialized/deserialized. - */ - @SmallTest - public void testMessageWithRequestIdHeader() { - final int xValue = 1; - final int yValue = 2; - final int type = 6; - final long requestId = 0x1deadbeafL; - Point p = new Point(); - p.x = xValue; - p.y = yValue; - MessageWithHeader message = p.serializeWithHeader(null, - new MessageHeader(type, MessageHeader.MESSAGE_EXPECTS_RESPONSE_FLAG, 0)); - message.setRequestId(requestId); - - MessageHeader header = message.getHeader(); - assertTrue(header.validateHeader(type, MessageHeader.MESSAGE_EXPECTS_RESPONSE_FLAG)); - assertEquals(type, header.getType()); - assertEquals(MessageHeader.MESSAGE_EXPECTS_RESPONSE_FLAG, header.getFlags()); - assertEquals(requestId, header.getRequestId()); - - Point p2 = Point.deserialize(message.getPayload()); - assertNotNull(p2); - assertEquals(p.x, p2.x); - assertEquals(p.y, p2.y); - } -} diff --git a/mojo/android/javatests/src/org/chromium/mojo/bindings/MessageWithHeaderTest.java b/mojo/android/javatests/src/org/chromium/mojo/bindings/MessageTest.java index 7f42445..ab2e871 100644 --- a/mojo/android/javatests/src/org/chromium/mojo/bindings/MessageWithHeaderTest.java +++ b/mojo/android/javatests/src/org/chromium/mojo/bindings/MessageTest.java @@ -7,6 +7,7 @@ package org.chromium.mojo.bindings; import android.test.suitebuilder.annotation.SmallTest; import org.chromium.mojo.MojoTestCase; +import org.chromium.mojo.TestUtils; import org.chromium.mojo.bindings.BindingsTestUtils.RecordingMessageReceiver; import org.chromium.mojo.system.Core; import org.chromium.mojo.system.DataPipe; @@ -23,9 +24,9 @@ import java.util.Arrays; import java.util.List; /** - * Testing {@link MessageWithHeader}. + * Testing {@link Message}. */ -public class MessageWithHeaderTest extends MojoTestCase { +public class MessageTest extends MojoTestCase { private static final int DATA_SIZE = 1024; @@ -42,7 +43,7 @@ public class MessageWithHeaderTest extends MojoTestCase { protected void setUp() throws Exception { super.setUp(); Core core = CoreImpl.getInstance(); - mData = BindingsTestUtils.newRandomMessageWithHeader(DATA_SIZE).getMessage().buffer; + mData = TestUtils.newRandomBuffer(DATA_SIZE); mMessageReceiver = new RecordingMessageReceiver(); mHandles = core.createMessagePipe(new MessagePipeHandle.CreateOptions()); Pair<DataPipe.ProducerHandle, DataPipe.ConsumerHandle> datapipe = core.createDataPipe(null); @@ -63,43 +64,43 @@ public class MessageWithHeaderTest extends MojoTestCase { } /** - * Testing {@link MessageWithHeader#readAndDispatchMessage(MessagePipeHandle, MessageReceiver)} + * Testing {@link Message#readAndDispatchMessage(MessagePipeHandle, MessageReceiver)} */ @SmallTest public void testReadAndDispatchMessage() { mHandles.first.writeMessage(mData, mHandlesToSend, MessagePipeHandle.WriteFlags.NONE); assertEquals(MojoResult.OK, - MessageWithHeader.readAndDispatchMessage(mHandles.second, mMessageReceiver)); + Message.readAndDispatchMessage(mHandles.second, mMessageReceiver)); assertEquals(1, mMessageReceiver.messages.size()); - MessageWithHeader message = mMessageReceiver.messages.get(0); - mHandlesToClose.addAll(message.getMessage().handles); - assertEquals(mData, message.getMessage().buffer); - assertEquals(2, message.getMessage().handles.size()); - for (Handle handle : message.getMessage().handles) { + Message message = mMessageReceiver.messages.get(0); + mHandlesToClose.addAll(message.handles); + assertEquals(mData, message.buffer); + assertEquals(2, message.handles.size()); + for (Handle handle : message.handles) { assertTrue(handle.isValid()); } } /** - * Testing {@link MessageWithHeader#readAndDispatchMessage(MessagePipeHandle, MessageReceiver)} - * with no message available. + * Testing {@link Message#readAndDispatchMessage(MessagePipeHandle, MessageReceiver)} with no + * message available. */ @SmallTest public void testReadAndDispatchMessageOnEmptyHandle() { assertEquals(MojoResult.SHOULD_WAIT, - MessageWithHeader.readAndDispatchMessage(mHandles.second, mMessageReceiver)); + Message.readAndDispatchMessage(mHandles.second, mMessageReceiver)); assertEquals(0, mMessageReceiver.messages.size()); } /** - * Testing {@link MessageWithHeader#readAndDispatchMessage(MessagePipeHandle, MessageReceiver)} - * on closed handle. + * Testing {@link Message#readAndDispatchMessage(MessagePipeHandle, MessageReceiver)} on closed + * handle. */ @SmallTest public void testReadAndDispatchMessageOnClosedHandle() { mHandles.first.close(); try { - MessageWithHeader.readAndDispatchMessage(mHandles.second, mMessageReceiver); + Message.readAndDispatchMessage(mHandles.second, mMessageReceiver); fail("MojoException should have been thrown"); } catch (MojoException expected) { assertEquals(MojoResult.FAILED_PRECONDITION, expected.getMojoResult()); diff --git a/mojo/android/javatests/src/org/chromium/mojo/bindings/RouterTest.java b/mojo/android/javatests/src/org/chromium/mojo/bindings/RouterTest.java deleted file mode 100644 index 58d3c71..0000000 --- a/mojo/android/javatests/src/org/chromium/mojo/bindings/RouterTest.java +++ /dev/null @@ -1,134 +0,0 @@ -// Copyright 2014 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -package org.chromium.mojo.bindings; - -import android.test.suitebuilder.annotation.SmallTest; - -import org.chromium.mojo.MojoTestCase; -import org.chromium.mojo.bindings.BindingsTestUtils.CapturingErrorHandler; -import org.chromium.mojo.bindings.BindingsTestUtils.RecordingMessageReceiverWithResponder; -import org.chromium.mojo.system.Core; -import org.chromium.mojo.system.Handle; -import org.chromium.mojo.system.MessagePipeHandle; -import org.chromium.mojo.system.MojoResult; -import org.chromium.mojo.system.Pair; -import org.chromium.mojo.system.impl.CoreImpl; - -import java.nio.ByteBuffer; -import java.util.ArrayList; - -/** - * Testing {@link Router} - */ -public class RouterTest extends MojoTestCase { - - private static final long RUN_LOOP_TIMEOUT_MS = 25; - - private MessagePipeHandle mHandle; - private Router mRouter; - private RecordingMessageReceiverWithResponder mReceiver; - private CapturingErrorHandler mErrorHandler; - - /** - * @see MojoTestCase#setUp() - */ - @Override - protected void setUp() throws Exception { - super.setUp(); - Core core = CoreImpl.getInstance(); - Pair<MessagePipeHandle, MessagePipeHandle> handles = core.createMessagePipe(null); - mHandle = handles.first; - mRouter = new RouterImpl(handles.second); - mReceiver = new RecordingMessageReceiverWithResponder(); - mRouter.setIncomingMessageReceiver(mReceiver); - mErrorHandler = new CapturingErrorHandler(); - mRouter.setErrorHandler(mErrorHandler); - mRouter.start(); - } - - /** - * Testing sending a message via the router that expected a response. - */ - @SmallTest - public void testSendingToRouterWithResponse() { - final int requestMessageType = 0xdead; - final int responseMessageType = 0xbeaf; - - // Sending a message expecting a response. - MessageHeader header = new MessageHeader(requestMessageType, - MessageHeader.MESSAGE_EXPECTS_RESPONSE_FLAG, 0); - Encoder encoder = new Encoder(CoreImpl.getInstance(), header.getSize()); - header.encode(encoder); - MessageWithHeader headerMessage = new MessageWithHeader(encoder.getMessage()); - mRouter.acceptWithResponder(headerMessage, mReceiver); - ByteBuffer receiveBuffer = ByteBuffer.allocateDirect(header.getSize()); - MessagePipeHandle.ReadMessageResult result = mHandle.readMessage(receiveBuffer, 0, - MessagePipeHandle.ReadFlags.NONE); - - assertEquals(MojoResult.OK, result.getMojoResult()); - MessageHeader receivedHeader = new MessageWithHeader( - new Message(receiveBuffer, new ArrayList<Handle>())) - .getHeader(); - - assertEquals(header.getType(), receivedHeader.getType()); - assertEquals(header.getFlags(), receivedHeader.getFlags()); - assertTrue(receivedHeader.getRequestId() != 0); - - // Sending the response. - MessageHeader responseHeader = new MessageHeader(responseMessageType, - MessageHeader.MESSAGE_IS_RESPONSE_FLAG, receivedHeader.getRequestId()); - encoder = new Encoder(CoreImpl.getInstance(), header.getSize()); - responseHeader.encode(encoder); - Message responseMessage = encoder.getMessage(); - mHandle.writeMessage(responseMessage.buffer, new ArrayList<Handle>(), - MessagePipeHandle.WriteFlags.NONE); - nativeRunLoop(RUN_LOOP_TIMEOUT_MS); - - assertEquals(1, mReceiver.messages.size()); - MessageWithHeader receivedResponseMessage = mReceiver.messages.get(0); - assertEquals(MessageHeader.MESSAGE_IS_RESPONSE_FLAG, - receivedResponseMessage.getHeader().getFlags()); - assertEquals(responseMessage.buffer, receivedResponseMessage.getMessage().buffer); - } - - /** - * Testing receiving a message via the router that expected a response. - */ - @SmallTest - public void testReceivingViaRouterWithResponse() { - final int requestMessageType = 0xdead; - final int responseMessageType = 0xbeef; - final int requestId = 0xdeadbeaf; - - // Sending a message expecting a response. - MessageHeader header = new MessageHeader(requestMessageType, - MessageHeader.MESSAGE_EXPECTS_RESPONSE_FLAG, requestId); - Encoder encoder = new Encoder(CoreImpl.getInstance(), header.getSize()); - header.encode(encoder); - Message headerMessage = encoder.getMessage(); - mHandle.writeMessage(headerMessage.buffer, new ArrayList<Handle>(), - MessagePipeHandle.WriteFlags.NONE); - nativeRunLoop(RUN_LOOP_TIMEOUT_MS); - - assertEquals(1, mReceiver.messagesWithReceivers.size()); - Pair<MessageWithHeader, MessageReceiver> receivedMessage = - mReceiver.messagesWithReceivers.get(0); - assertEquals(headerMessage.buffer, receivedMessage.first.getMessage().buffer); - - // Sending the response. - MessageHeader responseHeader = new MessageHeader(responseMessageType, - MessageHeader.MESSAGE_EXPECTS_RESPONSE_FLAG, requestId); - encoder = new Encoder(CoreImpl.getInstance(), header.getSize()); - responseHeader.encode(encoder); - MessageWithHeader responseHeaderMessage = new MessageWithHeader(encoder.getMessage()); - receivedMessage.second.accept(responseHeaderMessage); - ByteBuffer receivedResponseMessage = ByteBuffer.allocateDirect(responseHeader.getSize()); - MessagePipeHandle.ReadMessageResult result = mHandle.readMessage(receivedResponseMessage, 0, - MessagePipeHandle.ReadFlags.NONE); - - assertEquals(MojoResult.OK, result.getMojoResult()); - assertEquals(responseHeaderMessage.getMessage().buffer, receivedResponseMessage); - } -} |