Permalink
Browse files

Fixes to get tests green again, still working on it :)

  • Loading branch information...
jakewins committed Apr 24, 2012
1 parent 3f26d85 commit 4547b5995f34681145b4f1c78232b9c441bd03a2
@@ -1,8 +1,6 @@
package org.neo4j.smack.handler;
-import org.neo4j.graphdb.Node;
import org.neo4j.graphdb.Transaction;
-import org.neo4j.kernel.AbstractGraphDatabase;
import org.neo4j.smack.Database;
import org.neo4j.smack.TransactionRegistry;
import org.neo4j.smack.event.DatabaseWork;
@@ -82,12 +80,12 @@ public void onEvent(DatabaseWork work) throws Exception
}
}
- private void dumpDb(final AbstractGraphDatabase gds) {
- for (Node node : gds.getAllNodes()) {
- System.out.println("node = " + node);
- for (String prop : node.getPropertyKeys()) {
- System.out.println(prop + ": "+node.getProperty(prop));
- }
- }
- }
+// private void dumpDb(final AbstractGraphDatabase gds) {
+// for (Node node : gds.getAllNodes()) {
+// System.out.println("node = " + node);
+// for (String prop : node.getPropertyKeys()) {
+// System.out.println(prop + ": "+node.getProperty(prop));
+// }
+// }
+// }
}
@@ -158,7 +158,9 @@ void reset(HttpVersion protocolVersion, InvocationVerb verb,
public HttpDecoder(WorkPublisher workBuffer)
{
- this(workBuffer, 4096, 8192, 8192, new HashSet<HttpHeaderName>(){{
+ this(workBuffer, 4096, 8192, 8192, new HashSet<HttpHeaderName>(){
+ private static final long serialVersionUID = 1L;
+ {
add(HttpHeaderNames.CONTENT_LENGTH);
add(HttpHeaderNames.CONNECTION);
}});
@@ -13,14 +13,6 @@
// can continue on the next line
// which is insane
// Some-other-header: 12
-
- private enum State {
- SKIP_INITIAL_WHITESPACE,
- READ_HEADER_NAME,
- SKIP_SPACE_AFTER_HEADER_NAME,
- READ_VALUE,
- SKIP_UNTIL_NEXT_HEADER_STARTS, STORE_HEADER
- }
private final HttpHeaderName [] headersToCareAbout;
private final int maxHeaderSize;
@@ -29,8 +21,6 @@
private HttpHeaderName headerName;
private int headerSize;
-
- private State state = State.SKIP_INITIAL_WHITESPACE;
public HttpHeaderDecoder(Set<HttpHeaderName> headersToCareAbout, int maxHeaderSize) {
@@ -47,7 +37,6 @@ public HttpHeaderDecoder(Set<HttpHeaderName> headersToCareAbout, int maxHeaderSi
public void decode(ChannelBuffer buf, HttpHeaderContainer output) throws TooLongFrameException {
int currentIndex,
lineStopIndex;
- char nextByte = 0;
headerName = null;
headerSize = 0;
@@ -166,13 +155,12 @@ private int readValue(ChannelBuffer buf, int currentIndex, int lineStopIndex)
value.reset();
char nextByte;
- valueLoop:
- while(currentIndex < lineStopIndex) {
+ while(currentIndex < lineStopIndex)
+ {
nextByte = (char)buf.getByte(currentIndex++);
-
-
value.append(nextByte);
}
+
return currentIndex;
}
@@ -232,7 +220,8 @@ private int readLine(ChannelBuffer buf) throws TooLongFrameException
nextByte = (char) buf.readByte();
headerSize ++;
- switch (nextByte) {
+ switch (nextByte)
+ {
case HttpTokens.CR:
nextByte = (char) buf.readByte();
headerSize ++;
@@ -19,23 +19,14 @@
*/
package org.neo4j.smack.http;
-import static org.jboss.netty.handler.codec.http.HttpHeaders.Names.CONTENT_TYPE;
-import static org.jboss.netty.handler.codec.http.HttpVersion.HTTP_1_1;
-
import java.util.concurrent.atomic.AtomicLong;
-import org.jboss.netty.buffer.ChannelBuffers;
import org.jboss.netty.channel.Channel;
-import org.jboss.netty.channel.ChannelFutureListener;
import org.jboss.netty.channel.ChannelHandlerContext;
import org.jboss.netty.channel.ChannelStateEvent;
import org.jboss.netty.channel.ExceptionEvent;
import org.jboss.netty.channel.MessageEvent;
import org.jboss.netty.channel.SimpleChannelHandler;
-import org.jboss.netty.handler.codec.http.DefaultHttpResponse;
-import org.jboss.netty.handler.codec.http.HttpResponse;
-import org.jboss.netty.handler.codec.http.HttpResponseStatus;
-import org.jboss.netty.util.CharsetUtil;
import org.neo4j.smack.WorkPublisher;
public class NettyHttpHandler extends SimpleChannelHandler {
@@ -80,14 +71,4 @@ public void exceptionCaught(ChannelHandlerContext ctx, ExceptionEvent e)
workBuffer.addFailure(connectionId, ch, cause);
}
- private void sendError(ChannelHandlerContext ctx, HttpResponseStatus status) {
- HttpResponse response = new DefaultHttpResponse(HTTP_1_1, status);
- response.setHeader(CONTENT_TYPE, "text/plain; charset=UTF-8");
- response.setContent(ChannelBuffers.copiedBuffer("Failure: " + status.toString() + "\r\n", CharsetUtil.UTF_8));
-
- // Close the connection as soon as the error message is sent.
- ctx.getChannel().write(response)
- .addListener(ChannelFutureListener.CLOSE);
- }
-
}
@@ -70,6 +70,8 @@ public void reset(String uri, Charset charset) {
this.uri = uri;
this.charset = charset;
+ this.params = null;
+ this.path = null;
}
private Map<String, List<String>> decodeParams(String s) {
@@ -112,7 +114,7 @@ public void reset(String uri, Charset charset) {
return params;
}
- private static String decodeComponent(String s, Charset charset) {
+ private String decodeComponent(String s, Charset charset) {
if (s == null) {
return "";
}
@@ -124,7 +126,7 @@ private static String decodeComponent(String s, Charset charset) {
}
}
- private static void addParam(Map<String, List<String>> params, String name, String value) {
+ private void addParam(Map<String, List<String>> params, String name, String value) {
List<String> values = params.get(name);
if (values == null) {
values = new ArrayList<String>(1); // Often there's only 1 value.
@@ -77,8 +77,8 @@ public void compileRoutes() {
// todo what happens if multiple paths have differnt verbs?
}
- for(RouteEntry route : routeMap.values())
- System.out.println(route);
+// for(RouteEntry route : routeMap.values())
+// System.out.println(route);
routes = routeMap.values().toArray(new RouteEntry[routeMap.size()]);
}
@@ -20,17 +20,18 @@
package org.neo4j.smack.serialization;
+import java.io.IOException;
+import java.util.Map;
+
+import javax.ws.rs.core.MediaType;
+
import org.codehaus.jackson.JsonFactory;
import org.codehaus.jackson.JsonGenerator;
import org.jboss.netty.buffer.ChannelBuffer;
import org.jboss.netty.buffer.ChannelBufferOutputStream;
import org.neo4j.graphdb.Node;
import org.neo4j.graphdb.Relationship;
-import javax.ws.rs.core.MediaType;
-import java.io.IOException;
-import java.util.Map;
-
public class JsonSerializer implements Serializer {
private final JsonGenerator generator;
@@ -46,7 +47,7 @@ public JsonSerializer(JsonFactory jsonFactory, ChannelBuffer output) throws Seri
}
@Override
- public void putEnum(Enum en) throws SerializationException {
+ public void putEnum(Enum<?> en) throws SerializationException {
}
@@ -20,15 +20,16 @@
package org.neo4j.smack.serialization;
-import org.neo4j.graphdb.Node;
-import org.neo4j.graphdb.Relationship;
+import java.util.Map;
import javax.ws.rs.core.MediaType;
-import java.util.Map;
+
+import org.neo4j.graphdb.Node;
+import org.neo4j.graphdb.Relationship;
public interface Serializer {
- void putEnum(Enum en) throws SerializationException;
+ void putEnum(Enum<?> en) throws SerializationException;
void putString(String string) throws SerializationException;
@@ -20,17 +20,18 @@
package org.neo4j.smack.serialization;
-import org.neo4j.graphdb.Node;
-import org.neo4j.graphdb.Relationship;
+import java.util.Map;
import javax.ws.rs.core.MediaType;
-import java.util.Map;
+
+import org.neo4j.graphdb.Node;
+import org.neo4j.graphdb.Relationship;
public class ToStringSerializer implements Serializer {
StringBuilder buffer = new StringBuilder();
@Override
- public void putEnum(Enum en) {
+ public void putEnum(Enum<?> en) {
}
@@ -25,6 +25,8 @@ public void testDecodeSingleHeader() throws Exception
buf.writeByte(HttpTokens.LF);
HttpHeaderDecoder decoder = new HttpHeaderDecoder(new HashSet<HttpHeaderName>() {
+ private static final long serialVersionUID = 1L;
+
{
add(HttpHeaderNames.CONTENT_LENGTH);
}
@@ -51,8 +53,12 @@ public void testDecodeMultipleHeaders() throws Exception
buf.writeBytes("Content-Length: 4".getBytes("ASCII"));
buf.writeByte(HttpTokens.CR);
buf.writeByte(HttpTokens.LF);
+ buf.writeByte(HttpTokens.CR);
+ buf.writeByte(HttpTokens.LF);
HttpHeaderDecoder decoder = new HttpHeaderDecoder(new HashSet<HttpHeaderName>() {
+ private static final long serialVersionUID = 1L;
+
{
add(HttpHeaderNames.CONTENT_LENGTH);
add(HttpHeaderNames.ACCEPT);
@@ -75,14 +81,18 @@ public void testDecodeMultipleMultilineHeaders() throws Exception
ChannelBuffer buf = ChannelBuffers.dynamicBuffer();
buf.writeBytes("Content-Length: this".getBytes("ASCII"));
- buf.writeBytes(" is a multiline string".getBytes("ASCII"));
+ buf.writeBytes(" is a multiline string".getBytes("ASCII"));
buf.writeByte(HttpTokens.CR);
buf.writeByte(HttpTokens.LF);
buf.writeBytes("Accept : stuff".getBytes("ASCII"));
buf.writeByte(HttpTokens.CR);
buf.writeByte(HttpTokens.LF);
+ buf.writeByte(HttpTokens.CR);
+ buf.writeByte(HttpTokens.LF);
HttpHeaderDecoder decoder = new HttpHeaderDecoder(new HashSet<HttpHeaderName>() {
+ private static final long serialVersionUID = 1L;
+
{
add(HttpHeaderNames.CONTENT_LENGTH);
add(HttpHeaderNames.ACCEPT);
@@ -105,8 +115,12 @@ public void testDecodeHeadersOnlySeparatedByLinefeed() throws Exception
buf.writeBytes("Accept : stuff".getBytes("ASCII"));
buf.writeByte(HttpTokens.LF);
+ buf.writeByte(HttpTokens.CR);
+ buf.writeByte(HttpTokens.LF);
HttpHeaderDecoder decoder = new HttpHeaderDecoder(new HashSet<HttpHeaderName>() {
+ private static final long serialVersionUID = 1L;
+
{
add(HttpHeaderNames.CONTENT_LENGTH);
add(HttpHeaderNames.ACCEPT);
@@ -0,0 +1,24 @@
+package org.neo4j.smack.routing;
+
+import static org.hamcrest.Matchers.is;
+import static org.junit.Assert.assertThat;
+
+import org.jboss.netty.util.CharsetUtil;
+import org.junit.Test;
+
+
+public class TestResettableQueryStringDecoder {
+
+ @Test
+ public void testDecodeAndReset() {
+ ResettableQueryStringDecoder decoder = new ResettableQueryStringDecoder();
+ decoder.reset("/db/data", CharsetUtil.UTF_8);
+
+ assertThat(decoder.getParameters().size(), is(0));
+
+ decoder.reset("/db/da", CharsetUtil.UTF_8);
+
+ assertThat(decoder.getParameters().size(), is(0));
+ }
+
+}
@@ -94,7 +94,7 @@ private double sendXRequestsPipelinedMultiThreaded(String uri,
long numRequests, int numThreads) throws InterruptedException
{
Thread [] runnables = new Thread[numThreads];
- final long numRequestsPerThread = (long) numRequests / numThreads;
+ final long numRequestsPerThread = numRequests / numThreads;
for(int i=0;i<numThreads;i++) {
runnables[i] = new Thread(new LoadGeneratingRunnable(i == 0, numRequestsPerThread, numThreads));
}

0 comments on commit 4547b59

Please sign in to comment.