junit: dispatch messages

This commit is contained in:
anna
2009-12-21 17:42:45 +03:00
parent 63bda52025
commit 85272394c3
76 changed files with 741 additions and 1296 deletions
@@ -15,7 +15,7 @@
*/
package com.intellij.rt.execution.junit;
import com.intellij.rt.execution.junit.segments.OutputObjectRegistryEx;
import com.intellij.rt.execution.junit.segments.OutputObjectRegistry;
import com.intellij.rt.execution.junit.segments.Packet;
public class ExceptionPacketFactory implements PacketFactory {
@@ -27,7 +27,7 @@ public class ExceptionPacketFactory implements PacketFactory {
myAssertion = assertion;
}
public Packet createPacket(OutputObjectRegistryEx registry, Object test) {
public Packet createPacket(OutputObjectRegistry registry, Object test) {
return registry.createPacket().
setTestState(test, myState).
addThrowable(myAssertion);
@@ -15,9 +15,9 @@
*/
package com.intellij.rt.execution.junit;
import com.intellij.rt.execution.junit.segments.OutputObjectRegistryEx;
import com.intellij.rt.execution.junit.segments.OutputObjectRegistry;
import com.intellij.rt.execution.junit.segments.Packet;
public interface PacketFactory {
Packet createPacket(OutputObjectRegistryEx registry, Object test);
Packet createPacket(OutputObjectRegistry registry, Object test);
}
@@ -1,34 +0,0 @@
/*
* Copyright 2000-2009 JetBrains s.r.o.
*
* 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.intellij.rt.execution.junit.segments;
import java.io.OutputStream;
import java.io.IOException;
public class EchoOutputStream extends OutputStream {
private final OutputStream myOut;
private final OutputStream myEcho;
public EchoOutputStream(OutputStream out, OutputStream echo) {
myOut = out;
myEcho = echo;
}
public synchronized void write(int b) throws IOException {
myOut.write(b);
myEcho.write(b);
}
}
@@ -15,7 +15,81 @@
*/
package com.intellij.rt.execution.junit.segments;
public interface OutputObjectRegistry {
import java.util.Hashtable;
String referenceTo(Object object);
public abstract class OutputObjectRegistry {
private final Hashtable myKnownKeys = new Hashtable();
private int myLastIndex = 0;
private PacketProcessor myMainTransport;
private PacketProcessor myAuxilaryTransport;
public OutputObjectRegistry(PacketProcessor transport) {
myMainTransport = transport;
}
public OutputObjectRegistry(PacketProcessor mainTransport, PacketProcessor auxilaryTransport) {
this(mainTransport);
myAuxilaryTransport = auxilaryTransport;
}
public String referenceTo(Object test) {
if (myKnownKeys.containsKey(test))
return (String) myKnownKeys.get(test);
return sendObject(test);
}
public Packet createPacket() {
return new Packet(myMainTransport, this);
}
private String sendObject(Object test) {
String key = String.valueOf(myLastIndex++);
myKnownKeys.put(test, key);
Packet packet = createPacket().addString(PoolOfDelimiters.OBJECT_PREFIX).addReference(key);
addStringRepresentation(test, packet);
packet.addLong(getTestCont(test));
sendViaAllTransports(packet);
return key;
}
protected abstract int getTestCont(Object test);
protected abstract void addStringRepresentation(Object test, Packet packet);
private void sendViaAllTransports(Packet packet) {
packet.send();
if (myAuxilaryTransport != null)
packet.sendThrough(myAuxilaryTransport);
}
protected static void addTestClass(Packet packet, String className) {
packet.
addLimitedString(PoolOfTestTypes.TEST_CLASS).
addLimitedString(className);
}
protected void addUnknownTest(Packet packet, Object test) {
packet.
addLimitedString(PoolOfTestTypes.UNKNOWN).
addLong(getTestCont(test)).
addLimitedString(test.getClass().getName());
}
protected static void addAllInPackage(Packet packet, String name) {
packet.
addLimitedString(PoolOfTestTypes.ALL_IN_PACKAGE).
addLimitedString(name);
}
protected static void addTestMethod(Packet packet, String methodName, String className) {
packet.
addLimitedString(PoolOfTestTypes.TEST_METHOD).
addLimitedString(methodName).
addLimitedString(className);
}
public void forget(Object test) {
myKnownKeys.remove(test);
}
}
@@ -1,95 +0,0 @@
/*
* Copyright 2000-2009 JetBrains s.r.o.
*
* 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.intellij.rt.execution.junit.segments;
import java.util.Hashtable;
public abstract class OutputObjectRegistryEx implements OutputObjectRegistry, PacketFactory {
private final Hashtable myKnownKeys = new Hashtable();
private int myLastIndex = 0;
private PacketProcessor myMainTransport;
private PacketProcessor myAuxilaryTransport;
public OutputObjectRegistryEx(PacketProcessor transport) {
myMainTransport = transport;
}
public OutputObjectRegistryEx(PacketProcessor mainTransport, PacketProcessor auxilaryTransport) {
this(mainTransport);
myAuxilaryTransport = auxilaryTransport;
}
public String referenceTo(Object test) {
if (myKnownKeys.containsKey(test))
return (String) myKnownKeys.get(test);
return sendObject(test);
}
public Packet createPacket() {
return new Packet(myMainTransport, this);
}
private String sendObject(Object test) {
String key = String.valueOf(myLastIndex++);
myKnownKeys.put(test, key);
Packet packet = createPacket().addString(PoolOfDelimiters.OBJECT_PREFIX).addReference(key);
addStringRepresentation(test, packet);
packet.addLong(getTestCont(test));
sendViaAllTransports(packet);
return key;
}
protected abstract int getTestCont(Object test);
protected abstract void addStringRepresentation(Object test, Packet packet);
private void sendViaAllTransports(Packet packet) {
packet.send();
if (myAuxilaryTransport != null)
packet.sendThrough(myAuxilaryTransport);
}
protected static void addTestClass(Packet packet, String className) {
packet.
addLimitedString(PoolOfTestTypes.TEST_CLASS).
addLimitedString(className);
}
protected void addUnknownTest(Packet packet, Object test) {
packet.
addLimitedString(PoolOfTestTypes.UNKNOWN).
addLong(getTestCont(test)).
addLimitedString(test.getClass().getName());
}
protected static void addAllInPackage(Packet packet, String name) {
packet.
addLimitedString(PoolOfTestTypes.ALL_IN_PACKAGE).
addLimitedString(name);
}
protected static void addTestMethod(Packet packet, String methodName, String className) {
packet.
addLimitedString(PoolOfTestTypes.TEST_METHOD).
addLimitedString(methodName).
addLimitedString(className);
}
public void forget(Object test) {
myKnownKeys.remove(test);
}
}
@@ -1,20 +0,0 @@
/*
* Copyright 2000-2009 JetBrains s.r.o.
*
* 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.intellij.rt.execution.junit.segments;
public interface PacketFactory {
Packet createPacket();
}
@@ -1,28 +0,0 @@
/*
* Copyright 2000-2009 JetBrains s.r.o.
*
* 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.intellij.rt.execution.junit.segments;
/**
* @author MYakovlev
* Date: Feb 27, 2003
* Time: 10:48:55 AM
*/
public class PacketProcessors{
public static final PacketProcessor DEAF = new PacketProcessor() {
public void processPacket(String packet) {
}
};
}
@@ -1,23 +0,0 @@
/*
* Copyright 2000-2009 JetBrains s.r.o.
*
* 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.intellij.rt.execution.junit.segments;
/**
* @noinspection HardCodedStringLiteral
*/
public interface PoolOfKnownObjects {
String DEFAULT_INPUT_CONSUMER = "K1";
}
@@ -75,24 +75,4 @@ public class SegmentedOutputStream extends OutputStream implements PacketProcess
writeNext(SegmentedStream.STARTUP_MESSAGE);
myStarted = true;
}
public void beNotStarted() {
myStarted = false;
}
public static interface PrintStreamProvider {
OutputStream getOutputStream();
}
public static class SimplePrintStreamProvider implements PrintStreamProvider {
private final PrintStream myPrintStream;
public SimplePrintStreamProvider(PrintStream printStream) {
myPrintStream = printStream;
}
public OutputStream getOutputStream() {
return myPrintStream;
}
}
}