// Path: src/main/java/com/yammer/httptunnel/util/WriteFragmenter.java
// public class WriteFragmenter extends SimpleChannelDownstreamHandler {
// 
// 	/**
// 	 * Splits the given buffer in to multiple chunks based on the split
// 	 * threshold.
// 	 */
// 	public static List<ChannelBuffer> split(ChannelBuffer buffer, int splitThreshold) {
// 		final int listSize = (int) ((float) buffer.readableBytes() / splitThreshold);
// 		final ArrayList<ChannelBuffer> fragmentList = new ArrayList<ChannelBuffer>(listSize);
// 
// 		if (buffer.readableBytes() > splitThreshold) {
// 			int slicePosition = buffer.readerIndex();
// 			while (slicePosition < buffer.writerIndex()) {
// 				final int chunkSize = Math.min(splitThreshold, buffer.writerIndex() - slicePosition);
// 				final ChannelBuffer chunk = buffer.slice(slicePosition, chunkSize);
// 
// 				fragmentList.add(chunk);
// 				slicePosition += chunkSize;
// 			}
// 		}
// 		else
// 			fragmentList.add(ChannelBuffers.wrappedBuffer(buffer));
// 
// 		return fragmentList;
// 	}
// 
// 	private int splitThreshold;
// 
// 	public WriteFragmenter(int splitThreshold) {
// 		this.splitThreshold = splitThreshold;
// 	}
// 
// 	public void setSplitThreshold(int splitThreshold) {
// 		this.splitThreshold = splitThreshold;
// 	}
// 
// 	@Override
// 	public void writeRequested(ChannelHandlerContext ctx, MessageEvent e) throws Exception {
// 		final ChannelBuffer data = (ChannelBuffer) e.getMessage();
// 
// 		if (data.readableBytes() <= splitThreshold)
// 			super.writeRequested(ctx, e);
// 		else {
// 			final List<ChannelBuffer> fragments = WriteFragmenter.split(data, splitThreshold);
// 			final ChannelFutureAggregator aggregator = new ChannelFutureAggregator(e.getFuture());
// 
// 			for (ChannelBuffer fragment : fragments) {
// 				final ChannelFuture fragmentFuture = Channels.future(ctx.getChannel(), true);
// 				aggregator.addFuture(fragmentFuture);
// 
// 				Channels.write(ctx, fragmentFuture, fragment);
// 			}
// 		}
// 	}
// }


import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import java.util.List;
import org.jboss.netty.buffer.ChannelBuffer;
import org.jboss.netty.buffer.ChannelBuffers;
import org.junit.Test;
import com.yammer.httptunnel.util.WriteFragmenter;
/*
 * Copyright 2009 Red Hat, Inc.
 *
 * Red Hat 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 com.yammer.httptunnel;





/**
 * @author The Netty Project (netty-dev@lists.jboss.org)
 * @author Iain McGinniss (iain.mcginniss@onedrum.com)
 */
public class WriteSplitterTest {

	private static final int SPLIT_THRESHOLD = 1024;

	@Test
	public void testSplit_bufferUnderThreshold() {
		ChannelBuffer buffer = createBufferWithContents(800);
// Path: src/main/java/com/yammer/httptunnel/util/WriteFragmenter.java
// public class WriteFragmenter extends SimpleChannelDownstreamHandler {
// 
// 	/**
// 	 * Splits the given buffer in to multiple chunks based on the split
// 	 * threshold.
// 	 */
// 	public static List<ChannelBuffer> split(ChannelBuffer buffer, int splitThreshold) {
// 		final int listSize = (int) ((float) buffer.readableBytes() / splitThreshold);
// 		final ArrayList<ChannelBuffer> fragmentList = new ArrayList<ChannelBuffer>(listSize);
// 
// 		if (buffer.readableBytes() > splitThreshold) {
// 			int slicePosition = buffer.readerIndex();
// 			while (slicePosition < buffer.writerIndex()) {
// 				final int chunkSize = Math.min(splitThreshold, buffer.writerIndex() - slicePosition);
// 				final ChannelBuffer chunk = buffer.slice(slicePosition, chunkSize);
// 
// 				fragmentList.add(chunk);
// 				slicePosition += chunkSize;
// 			}
// 		}
// 		else
// 			fragmentList.add(ChannelBuffers.wrappedBuffer(buffer));
// 
// 		return fragmentList;
// 	}
// 
// 	private int splitThreshold;
// 
// 	public WriteFragmenter(int splitThreshold) {
// 		this.splitThreshold = splitThreshold;
// 	}
// 
// 	public void setSplitThreshold(int splitThreshold) {
// 		this.splitThreshold = splitThreshold;
// 	}
// 
// 	@Override
// 	public void writeRequested(ChannelHandlerContext ctx, MessageEvent e) throws Exception {
// 		final ChannelBuffer data = (ChannelBuffer) e.getMessage();
// 
// 		if (data.readableBytes() <= splitThreshold)
// 			super.writeRequested(ctx, e);
// 		else {
// 			final List<ChannelBuffer> fragments = WriteFragmenter.split(data, splitThreshold);
// 			final ChannelFutureAggregator aggregator = new ChannelFutureAggregator(e.getFuture());
// 
// 			for (ChannelBuffer fragment : fragments) {
// 				final ChannelFuture fragmentFuture = Channels.future(ctx.getChannel(), true);
// 				aggregator.addFuture(fragmentFuture);
// 
// 				Channels.write(ctx, fragmentFuture, fragment);
// 			}
// 		}
// 	}
// }


// Path: src/test/java/com/yammer/httptunnel/WriteSplitterTest.java
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import java.util.List;
import org.jboss.netty.buffer.ChannelBuffer;
import org.jboss.netty.buffer.ChannelBuffers;
import org.junit.Test;
import com.yammer.httptunnel.util.WriteFragmenter;

/*
 * Copyright 2009 Red Hat, Inc.
 *
 * Red Hat 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 com.yammer.httptunnel;





/**
 * @author The Netty Project (netty-dev@lists.jboss.org)
 * @author Iain McGinniss (iain.mcginniss@onedrum.com)
 */
public class WriteSplitterTest {

	private static final int SPLIT_THRESHOLD = 1024;

	@Test
	public void testSplit_bufferUnderThreshold() {
		ChannelBuffer buffer = createBufferWithContents(800);
		List<ChannelBuffer> fragments = WriteFragmenter.split(buffer,