PROTON-1811 Refactor FrameWriter to reduce code on hot path

Refactoring the FrameWriter to reduce the code on hot path like logging
which isn't normally enabled.  Eliminate allocations of EmptyFrame.

Adds modified JUnit test to allow for running the python tests in an IDE
to aid debugging test failures.
diff --git a/proton-j/src/main/java/org/apache/qpid/proton/amqp/transport/EmptyFrame.java b/proton-j/src/main/java/org/apache/qpid/proton/amqp/transport/EmptyFrame.java
index b085e84..bb76ba9 100644
--- a/proton-j/src/main/java/org/apache/qpid/proton/amqp/transport/EmptyFrame.java
+++ b/proton-j/src/main/java/org/apache/qpid/proton/amqp/transport/EmptyFrame.java
@@ -24,6 +24,8 @@
 
 public final class EmptyFrame implements FrameBody
 {
+    public static final EmptyFrame INSTANCE = new EmptyFrame();
+
     @Override
     public <E> void invoke(FrameBodyHandler<E> handler, Binary payload, E context)
     {
diff --git a/proton-j/src/main/java/org/apache/qpid/proton/engine/impl/FrameParser.java b/proton-j/src/main/java/org/apache/qpid/proton/engine/impl/FrameParser.java
index 51ad06e..38760f8 100644
--- a/proton-j/src/main/java/org/apache/qpid/proton/engine/impl/FrameParser.java
+++ b/proton-j/src/main/java/org/apache/qpid/proton/engine/impl/FrameParser.java
@@ -401,7 +401,7 @@
                         }
                         else
                         {
-                            val = new EmptyFrame();
+                            val = EmptyFrame.INSTANCE;
                         }
 
                         if(val instanceof FrameBody)
diff --git a/proton-j/src/main/java/org/apache/qpid/proton/engine/impl/FrameWriter.java b/proton-j/src/main/java/org/apache/qpid/proton/engine/impl/FrameWriter.java
index f568b1c..eb16624 100644
--- a/proton-j/src/main/java/org/apache/qpid/proton/engine/impl/FrameWriter.java
+++ b/proton-j/src/main/java/org/apache/qpid/proton/engine/impl/FrameWriter.java
@@ -34,7 +34,6 @@
  * FrameWriter
  *
  */
-
 class FrameWriter
 {
 
@@ -97,7 +96,7 @@
         _frameStart = _buffer.position();
     }
 
-    private void writePerformative(Object frameBody)
+    private void writePerformative(Object frameBody, ByteBuffer payload, Runnable onPayloadTooLarge)
     {
         while (_buffer.remaining() < 8) {
             grow();
@@ -109,16 +108,30 @@
             {
                 _buffer.position(_frameStart + 8);
                 if (frameBody != null) _encoder.writeObject(frameBody);
-                break;
+
+                _payloadStart = _buffer.position();
+                _performativeSize = _payloadStart - _frameStart;
+
+                if (onPayloadTooLarge == null)
+                {
+                    break;
+                }
+
+                if (_maxFrameSize > 0 && payload != null && (payload.remaining() + _performativeSize) > _maxFrameSize)
+                {
+                    onPayloadTooLarge.run();
+                    onPayloadTooLarge = null;
+                }
+                else
+                {
+                    break;
+                }
             }
             catch (BufferOverflowException e)
             {
                 grow();
             }
         }
-
-        _payloadStart = _buffer.position();
-        _performativeSize = _payloadStart - _frameStart;
     }
 
     private void endFrame(int channel)
@@ -138,16 +151,7 @@
     {
         startFrame();
 
-        writePerformative(frameBody);
-
-        if(_maxFrameSize > 0 && payload != null && (payload.remaining() + _performativeSize) > _maxFrameSize)
-        {
-            if(onPayloadTooLarge != null)
-            {
-                onPayloadTooLarge.run();
-            }
-            writePerformative(frameBody);
-        }
+        writePerformative(frameBody, payload, onPayloadTooLarge);
 
         int capacity;
         if (_maxFrameSize > 0) {
@@ -158,39 +162,9 @@
         int payloadSize = Math.min(payload == null ? 0 : payload.remaining(), capacity);
 
         ProtocolTracer tracer = _protocolTracer == null ? null : _protocolTracer.get();
-        if( tracer != null || _transport.isTraceFramesEnabled())
+        if(tracer != null || _transport.isTraceFramesEnabled())
         {
-            // XXX: this is a bit of a hack but it eliminates duplicate
-            // code, further refactor will fix this
-            if (_frameType == AMQP_FRAME_TYPE)
-            {
-                ByteBuffer originalPayload = null;
-                if( payload!=null )
-                {
-                    originalPayload = payload.duplicate();
-                    originalPayload.limit(payload.position() + payloadSize);
-                }
-
-                Binary payloadBin = Binary.create(originalPayload);
-                FrameBody body = null;
-                if (frameBody == null)
-                {
-                    body = new EmptyFrame();
-                }
-                else
-                {
-                    body = (FrameBody) frameBody;
-                }
-
-                TransportFrame frame = new TransportFrame(channel, body, payloadBin);
-
-                _transport.log(TransportImpl.OUTGOING, frame);
-
-                if(tracer != null)
-                {
-                    tracer.sentFrame(frame);
-                }
-            }
+            logFrame(tracer, channel, frameBody, payload, payloadSize);
         }
 
         if(payloadSize > 0)
@@ -211,6 +185,41 @@
         _framesOutput += 1;
     }
 
+    private void logFrame(ProtocolTracer tracer, int channel, Object frameBody, ByteBuffer payload, int payloadSize)
+    {
+        // XXX: this is a bit of a hack but it eliminates duplicate
+        // code, further refactor will fix this
+        if (_frameType == AMQP_FRAME_TYPE)
+        {
+            ByteBuffer originalPayload = null;
+            if (payload!=null)
+            {
+                originalPayload = payload.duplicate();
+                originalPayload.limit(payload.position() + payloadSize);
+            }
+
+            Binary payloadBin = Binary.create(originalPayload);
+            FrameBody body = null;
+            if (frameBody == null)
+            {
+                body = EmptyFrame.INSTANCE;
+            }
+            else
+            {
+                body = (FrameBody) frameBody;
+            }
+
+            TransportFrame frame = new TransportFrame(channel, body, payloadBin);
+
+            _transport.log(TransportImpl.OUTGOING, frame);
+
+            if (tracer != null)
+            {
+                tracer.sentFrame(frame);
+            }
+        }
+    }
+
     void writeFrame(Object frameBody)
     {
         writeFrame(0, frameBody, null, null);
diff --git a/tests/java/org/apache/qpid/proton/JythonIDETest.java b/tests/java/org/apache/qpid/proton/JythonIDETest.java
new file mode 100644
index 0000000..94995ec
--- /dev/null
+++ b/tests/java/org/apache/qpid/proton/JythonIDETest.java
@@ -0,0 +1,130 @@
+/*
+ * 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.qpid.proton;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Ignore;
+import org.junit.Test;
+
+/**
+ * IDE Runner for python based tests by loading test resources from the mvn configured base
+ * directory
+ */
+@Ignore
+public class JythonIDETest extends JythonTest {
+
+    @Before
+    public void setUp() {
+        System.setProperty(PROTON_JYTHON_BINDING, "java/shim/binding");
+        System.setProperty(PROTON_JYTHON_SHIM, "java/shim");
+        System.setProperty(PROTON_JYTHON_TEST_ROOT, "python/");
+        System.setProperty(PROTON_JYTHON_TEST_SCRIPT, "python/proton-test");
+        System.setProperty(PROTON_JYTHON_IGNORE_FILE, "java/pythonTests.ignore");
+    }
+
+    @After
+    public void tearDown() {
+        System.clearProperty(PROTON_JYTHON_BINDING);
+        System.clearProperty(PROTON_JYTHON_SHIM);
+        System.clearProperty(PROTON_JYTHON_TEST_ROOT);
+        System.clearProperty(PROTON_JYTHON_TEST_SCRIPT);
+        System.clearProperty(TEST_PATTERN_SYSTEM_PROPERTY);
+    }
+
+    @Ignore
+    @Test
+    public void test() {}
+
+    @Test
+    public void testConnectionTest() throws Exception {
+        System.setProperty(TEST_PATTERN_SYSTEM_PROPERTY, "proton_tests.engine.ConnectionTest.*");
+        super.test();
+    }
+
+    @Test
+    public void testSessionTests() throws Exception {
+        System.setProperty(TEST_PATTERN_SYSTEM_PROPERTY, "proton_tests.engine.SessionTest.*");
+        super.test();
+    }
+
+    @Test
+    public void testTransferTests() throws Exception {
+        System.setProperty(TEST_PATTERN_SYSTEM_PROPERTY, "proton_tests.engine.TransferTest.*");
+        super.test();
+    }
+
+    @Test
+    public void testSettlementTests() throws Exception {
+        System.setProperty(TEST_PATTERN_SYSTEM_PROPERTY, "proton_tests.engine.SettlementTest.*");
+        super.test();
+    }
+
+    @Test
+    public void testSessionCreditTest() throws Exception {
+        System.setProperty(TEST_PATTERN_SYSTEM_PROPERTY, "proton_tests.engine.SessionCreditTest.*");
+        super.test();
+    }
+
+    @Test
+    public void testLinkTests() throws Exception {
+        System.setProperty(TEST_PATTERN_SYSTEM_PROPERTY, "proton_tests.engine.LinkTest.*");
+        super.test();
+    }
+
+    @Test
+    public void testEventTest() throws Exception {
+        System.setProperty(TEST_PATTERN_SYSTEM_PROPERTY, "proton_tests.engine.EventTest.*");
+        super.test();
+    }
+
+    @Test
+    public void testDeliveryTests() throws Exception {
+        System.setProperty(TEST_PATTERN_SYSTEM_PROPERTY, "proton_tests.engine.DeliveryTest.*");
+        super.test();
+    }
+
+    @Test
+    public void testCreditTests() throws Exception {
+        System.setProperty(TEST_PATTERN_SYSTEM_PROPERTY, "proton_tests.engine.CreditTest.*");
+        super.test();
+    }
+
+    @Test
+    public void testCodecDataTests() throws Exception {
+        System.setProperty(TEST_PATTERN_SYSTEM_PROPERTY, "proton_tests.codec.DataTest.*");
+        super.test();
+    }
+
+    @Test
+    public void testInteropTests() throws Exception {
+        System.setProperty(TEST_PATTERN_SYSTEM_PROPERTY, "proton_tests.interop.InteropTest.*");
+        super.test();
+    }
+
+    @Test
+    public void testClientTransportTests() throws Exception {
+        System.setProperty(TEST_PATTERN_SYSTEM_PROPERTY, "proton_tests.transport.ClientTransportTest.*");
+        super.test();
+    }
+
+    @Test
+    public void testMaxFrameTransferTests() throws Exception {
+        System.setProperty(TEST_PATTERN_SYSTEM_PROPERTY, "proton_tests.engine.MaxFrameTransferTest.*");
+        super.test();
+    }
+}
diff --git a/tests/java/org/apache/qpid/proton/JythonTest.java b/tests/java/org/apache/qpid/proton/JythonTest.java
index 23eceab..3741989 100644
--- a/tests/java/org/apache/qpid/proton/JythonTest.java
+++ b/tests/java/org/apache/qpid/proton/JythonTest.java
@@ -45,15 +45,16 @@
     public interface PathBuilder {
         public PathBuilder append(String path);
     }
+
     private static final Logger LOGGER = Logger.getLogger(JythonTest.class.getName());
 
     /* System properties expected to be defined in test/pom.xml */
-    private static final String PROTON_JYTHON_BINDING = "protonJythonBinding";
-    private static final String PROTON_JYTHON_SHIM = "protonJythonShim";
-    private static final String PROTON_JYTHON_TEST_ROOT = "protonJythonTestRoot";
-    private static final String PROTON_JYTHON_TEST_SCRIPT = "protonJythonTestScript";
-    private static final String PROTON_JYTHON_TESTS_XML_OUTPUT_DIRECTORY = "protonJythonTestXmlOutputDirectory";
-    private static final String PROTON_JYTHON_IGNORE_FILE = "protonJythonIgnoreFile";
+    protected static final String PROTON_JYTHON_BINDING = "protonJythonBinding";
+    protected static final String PROTON_JYTHON_SHIM = "protonJythonShim";
+    protected static final String PROTON_JYTHON_TEST_ROOT = "protonJythonTestRoot";
+    protected static final String PROTON_JYTHON_TEST_SCRIPT = "protonJythonTestScript";
+    protected static final String PROTON_JYTHON_TESTS_XML_OUTPUT_DIRECTORY = "protonJythonTestXmlOutputDirectory";
+    protected static final String PROTON_JYTHON_IGNORE_FILE = "protonJythonIgnoreFile";
 
     /** Name of the junit style xml report to be written by the python test script */
     private static final String XML_REPORT_NAME = "TEST-jython-test-results.xml";
@@ -208,7 +209,6 @@
         return file.getAbsolutePath();
     }
 
-
     private String getJythonTestRoot() throws FileNotFoundException
     {
         String testRootString = getNonNullSystemProperty(PROTON_JYTHON_TEST_ROOT, "System property '%s' must provide the location of the python test root");
@@ -237,7 +237,7 @@
             }
         }
         return null;
-        
+
     }
 
     private String getOptionalXmlReportFilename()
@@ -246,11 +246,14 @@
         if (xmlOutputDirString == null)
         {
             LOGGER.info(PROTON_JYTHON_TESTS_XML_OUTPUT_DIRECTORY + " system property not set; xml output will not be written");
+            return null;
         }
-
-        File xmlOutputDir = new File(xmlOutputDirString);
-        createXmlOutputDirectoryIfNecessary(xmlOutputDirString, xmlOutputDir);
-        return new File(xmlOutputDir, XML_REPORT_NAME).getAbsolutePath();
+        else
+        {
+            File xmlOutputDir = new File(xmlOutputDirString);
+            createXmlOutputDirectoryIfNecessary(xmlOutputDirString, xmlOutputDir);
+            return new File(xmlOutputDir, XML_REPORT_NAME).getAbsolutePath();
+        }
     }
 
     private void createXmlOutputDirectoryIfNecessary(String xmlOutputDirString, File xmlOutputDir)