Java Code Examples for java.nio.IntBuffer#put()

The following examples show how to use java.nio.IntBuffer#put() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TestBufferDirectSequentialNumberCellIndexInteger.java    From yosegi with Apache License 2.0 6 votes vote down vote up
@Test
public void T_int_filter_6() throws IOException{
  List<PrimitiveObject> dic = new ArrayList<PrimitiveObject>();
  dic.add( new IntegerObj( 1000 ) );
  dic.add( new IntegerObj( 2000 ) );
  dic.add( new IntegerObj( 3000 ) );
  dic.add( new IntegerObj( 4000 ) );
  dic.add( new IntegerObj( 5000 ) );
  IntBuffer buffer = IntBuffer.allocate( 100 );
  for( int i = 0 ; i < 100 ; i++ ){
    buffer.put( i % 5 );
  }
  ICellIndex index = new BufferDirectSequentialNumberCellIndex( ColumnType.INTEGER , new TestDicManager( dic ) , buffer );
  IFilter filter = new NumberFilter( NumberFilterType.GE , new IntegerObj( 4000 ) );

  FilterdExpressionIndex result = new FilterdExpressionIndex( index.filter( filter , new boolean[100] ) );
  assertEquals( result.size() , 40 );
  for( int i = 0,n=0 ; n < 100 ; i+=2,n+=5 ){
    assertEquals( result.get(i) , n+3 );
    assertEquals( result.get(i+1) , n+4 );
  }
}
 
Example 2
Source File: MockMxnetLibrary.java    From djl with Apache License 2.0 6 votes vote down vote up
/** {@inheritDoc} */
@Override
public int MXInvokeCachedOp(
        Pointer handle,
        int num_inputs,
        Pointer inputs,
        IntBuffer num_outputs,
        PointerByReference outputs) {
    if (functions.containsKey("MXInvokeCachedOp")) {
        return functions
                .get("MXInvokeCachedOp")
                .apply(new Object[] {handle, num_inputs, inputs, num_outputs, outputs});
    }

    num_outputs.put(0, 3);
    PointerArray arr =
            new PointerArray(
                    TestHelper.toPointer("a"),
                    TestHelper.toPointer("b"),
                    TestHelper.toPointer("c"));
    outputs.setValue(arr);
    return 0;
}
 
Example 3
Source File: BufferUtils.java    From aion-germany with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Creates a new IntBuffer with the same contents as the given IntBuffer. The new IntBuffer is seperate from the old one and changes are not reflected across. If you want to reflect changes,
 * consider using Buffer.duplicate().
 *
 * @param buf
 *            the IntBuffer to copy
 * @return the copy
 */
public static IntBuffer clone(IntBuffer buf) {
	if (buf == null) {
		return null;
	}
	buf.rewind();

	IntBuffer copy;
	if (buf.isDirect()) {
		copy = createIntBuffer(buf.limit());
	}
	else {
		copy = IntBuffer.allocate(buf.limit());
	}
	copy.put(buf);

	return copy;
}
 
Example 4
Source File: TestBufferDirectSequentialNumberCellIndexInteger.java    From yosegi with Apache License 2.0 6 votes vote down vote up
@Test
public void T_int_filter_1() throws IOException{
  List<PrimitiveObject> dic = new ArrayList<PrimitiveObject>();
  dic.add( new IntegerObj( 1000 ) );
  dic.add( new IntegerObj( 2000 ) );
  dic.add( new IntegerObj( 3000 ) );
  dic.add( new IntegerObj( 4000 ) );
  dic.add( new IntegerObj( 5000 ) );
  IntBuffer buffer = IntBuffer.allocate( 100 );
  for( int i = 0 ; i < 100 ; i++ ){
    buffer.put( i % 5 );
  }
  ICellIndex index = new BufferDirectSequentialNumberCellIndex( ColumnType.INTEGER , new TestDicManager( dic ) , buffer );
  IFilter filter = new NumberFilter( NumberFilterType.EQUAL , new IntegerObj( 1000 ) );

  FilterdExpressionIndex result = new FilterdExpressionIndex( index.filter( filter , new boolean[100] ) );
  assertEquals( result.size() , 20 );
  for( int i = 0,n=0 ; n < 100 ; i++,n+=5 ){
    assertEquals( result.get(i) , n );
  }
}
 
Example 5
Source File: TestBufferDirectSequentialNumberCellIndexShort.java    From yosegi with Apache License 2.0 6 votes vote down vote up
@Test
public void T_short_filter_2() throws IOException{
  List<PrimitiveObject> dic = new ArrayList<PrimitiveObject>();
  dic.add( new ShortObj( (short) 1000 ) );
  dic.add( new ShortObj( (short) 2000 ) );
  dic.add( new ShortObj( (short) 3000 ) );
  dic.add( new ShortObj( (short) 4000 ) );
  dic.add( new ShortObj( (short) 5000 ) );
  IntBuffer buffer = IntBuffer.allocate( 100 );
  for( int i = 0 ; i < 100 ; i++ ){
    buffer.put( i % 5 );
  }
  ICellIndex index = new BufferDirectSequentialNumberCellIndex( ColumnType.SHORT , new TestDicManager( dic ) , buffer );
  IFilter filter = new NumberFilter( NumberFilterType.NOT_EQUAL , new ShortObj( (short) 1000 ) );

  FilterdExpressionIndex result = new FilterdExpressionIndex( index.filter( filter , new boolean[100] ) );
  assertEquals( result.size() , 80 );
  for( int i = 0,n=0 ; n < 100 ; i+=4,n+=5 ){
    assertEquals( result.get(i) , n + 1 );
    assertEquals( result.get(i+1) , n + 2 );
    assertEquals( result.get(i+2) , n + 3 );
    assertEquals( result.get(i+3) , n + 4 );
  }
}
 
Example 6
Source File: Object3DBuilder.java    From react-native-3d-model-view with MIT License 6 votes vote down vote up
/**
 * Build a wireframe from obj vertices and faces.  This method uses less memory that {@link #buildWireframe(Object3DData)}
 * --The problem-- in using this method  is that we are reshaping the object (scaling) after
 * it is loaded, so this wireframe wont match current state of the shape
 * @param objData the 3d model
 * @return the 3d wireframe
 */
public static Object3DData buildWireframe_from_original(Object3DData objData) {
	try {
		IntBuffer drawOrder = createNativeByteBuffer(objData.getFaces().getIndexBuffer().capacity() * 2 * 4).asIntBuffer();
		for (int i = 0; i < objData.getFaces().getIndexBuffer().capacity(); i+=3) {
				drawOrder.put(objData.getFaces().getIndexBuffer().get(i));
				drawOrder.put((objData.getFaces().getIndexBuffer().get(i+1)));
				drawOrder.put((objData.getFaces().getIndexBuffer().get(i+1)));
				drawOrder.put((objData.getFaces().getIndexBuffer().get(i+2)));
				drawOrder.put((objData.getFaces().getIndexBuffer().get(i+2)));
				drawOrder.put((objData.getFaces().getIndexBuffer().get(i)));
		}
		return new Object3DData(objData.getVertexBuffer()).setDrawOrder(drawOrder).
				setVertexNormalsArrayBuffer(objData.getVertexNormalsBuffer()).setColor(objData.getColor())
				.setDrawMode(GLES20.GL_LINES);
	} catch (Exception ex) {
		Log.e("Object3DBuilder", ex.getMessage(), ex);
	}
	return objData;
}
 
Example 7
Source File: TestBufferDirectSequentialNumberCellIndexByte.java    From yosegi with Apache License 2.0 6 votes vote down vote up
@Test
public void T_byte_filter_3() throws IOException{
  List<PrimitiveObject> dic = new ArrayList<PrimitiveObject>();
  dic.add( new ByteObj( (byte) 10 ) );
  dic.add( new ByteObj( (byte) 20 ) );
  dic.add( new ByteObj( (byte) 30 ) );
  dic.add( new ByteObj( (byte) 40 ) );
  dic.add( new ByteObj( (byte) 50 ) );
  IntBuffer buffer = IntBuffer.allocate( 100 );
  for( int i = 0 ; i < 100 ; i++ ){
    buffer.put( i % 5 );
  }
  ICellIndex index = new BufferDirectSequentialNumberCellIndex( ColumnType.BYTE , new TestDicManager( dic ) , buffer );
  IFilter filter = new NumberFilter( NumberFilterType.LT , new ByteObj( (byte) 20 ) );

  FilterdExpressionIndex result = new FilterdExpressionIndex( index.filter( filter , new boolean[100] ) );
  assertEquals( result.size() , 20 );
  for( int i = 0,n=0 ; n < 100 ; i++,n+=5 ){
    assertEquals( result.get(i) , n );
  }
}
 
Example 8
Source File: LineBatcher.java    From constellation with Apache License 2.0 5 votes vote down vote up
private int bufferConnectionInfo(final int pos, final IntBuffer dataBuffer, final VisualAccess access) {
    if (connectionPosToBufferPos.containsKey(pos)) {
        final float width = Math.min(LabelUtilities.MAX_TRANSACTION_WIDTH, access.getConnectionWidth(pos));
        final float offset;
        if (leftOffset == 0) {
            offset = 0;
            leftOffset += width / 2;
            rightOffset = leftOffset;
        } else if (leftOffset < rightOffset) {
            offset = -(leftOffset + width / 2 + 1);
            leftOffset += width + 1;
        } else {
            offset = rightOffset + width / 2 + 1;
            rightOffset += width + 1;
        }

        final int representativeTransactionId = access.getConnectionId(pos);
        final int lowVertex = access.getConnectionLowVertex(pos);
        final int highVertex = access.getConnectionHighVertex(pos);
        final int flags = (access.getConnectionDimmed(pos) ? 2 : 0) | (access.getConnectionSelected(pos) ? 1 : 0);
        final int lineStyle = access.getConnectionLineStyle(pos).ordinal();
        final ConnectionDirection connectionDirection = access.getConnectionDirection(pos);

        dataBuffer.put(representativeTransactionId);
        dataBuffer.put(lowVertex * LINE_INFO_BITS_AVOID + ((connectionDirection == ConnectionDirection.LOW_TO_HIGH || connectionDirection == ConnectionDirection.BIDIRECTED) ? LINE_INFO_ARROW : 0));
        dataBuffer.put(flags);
        dataBuffer.put((int) (offset * FLOAT_MULTIPLIER));
        dataBuffer.put(representativeTransactionId);
        dataBuffer.put(highVertex * LINE_INFO_BITS_AVOID + ((connectionDirection == ConnectionDirection.HIGH_TO_LOW || connectionDirection == ConnectionDirection.BIDIRECTED) ? LINE_INFO_ARROW : 0));
        dataBuffer.put(flags);
        dataBuffer.put(((int) (width * FLOAT_MULTIPLIER)) << 2 | lineStyle);
        return connectionPosToBufferPos.get(pos);
    }
    return -1;
}
 
Example 9
Source File: BufferUtils.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Generate a new IntBuffer using the given array of ints. The IntBuffer
 * will be data.length long and contain the int data as data[0], data[1]...
 * etc.
 *
 * @param data
 *            array of ints to place into a new IntBuffer
 * @return a new direct, flipped IntBuffer, or null if data was null
 */
public static IntBuffer createIntBuffer(int... data) {
    if (data == null) {
        return null;
    }
    IntBuffer buff = createIntBuffer(data.length);
    buff.clear();
    buff.put(data);
    buff.flip();
    return buff;
}
 
Example 10
Source File: RandomAccessByteStreamTest.java    From succinct with Apache License 2.0 5 votes vote down vote up
public void testGetInt1() throws Exception {
  IntBuffer buf = IntBuffer.allocate(10);
  for (int i = 0; i < 10; i++) {
    buf.put(i);
  }
  FSDataInputStream is = TestUtils.getStream(buf);
  RandomAccessByteStream bs = new RandomAccessByteStream(is, 0, 40);
  for (int i = 0; i < 10; i++) {
    assertEquals(i, bs.getInt(i * 4));
  }
}
 
Example 11
Source File: Bert.java    From easy-bert with MIT License 5 votes vote down vote up
private Inputs getInputs(final String sequence) {
    final String[] tokens = tokenizer.tokenize(sequence);

    final IntBuffer inputIds = IntBuffer.allocate(model.maxSequenceLength);
    final IntBuffer inputMask = IntBuffer.allocate(model.maxSequenceLength);
    final IntBuffer segmentIds = IntBuffer.allocate(model.maxSequenceLength);

    /*
     * In BERT:
     * inputIds are the indexes in the vocabulary for each token in the sequence
     * inputMask is a binary mask that shows which inputIds have valid data in them
     * segmentIds are meant to distinguish paired sequences during training tasks. Here they're always 0 since we're only doing inference.
     */
    final int[] ids = tokenizer.convert(tokens);
    inputIds.put(startTokenId);
    inputMask.put(1);
    segmentIds.put(0);
    for(int i = 0; i < ids.length && i < model.maxSequenceLength - 2; i++) {
        inputIds.put(ids[i]);
        inputMask.put(1);
        segmentIds.put(0);
    }
    inputIds.put(separatorTokenId);
    inputMask.put(1);
    segmentIds.put(0);

    while(inputIds.position() < model.maxSequenceLength) {
        inputIds.put(0);
        inputMask.put(0);
        segmentIds.put(0);
    }

    inputIds.rewind();
    inputMask.rewind();
    segmentIds.rewind();

    return new Inputs(inputIds, inputMask, segmentIds, 1);
}
 
Example 12
Source File: IosGL.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private void fromArray(int n, int[] array, IntBuffer buffer) {
    if (buffer.remaining() < n) { 
        throw new BufferOverflowException();
    }
    int pos = buffer.position();
    buffer.put(array, 0, n);
    buffer.position(pos);
}
 
Example 13
Source File: UnsafeOptimizeDoubleColumnBinaryMaker.java    From multiple-dimension-spread with Apache License 2.0 5 votes vote down vote up
@Override
public IntBuffer getIndexIntBuffer( final byte[] buffer , final int start , final int length , ByteOrder order ) throws IOException{
  int size = length / Integer.BYTES;
  IReadSupporter wrapBuffer = ByteBufferSupporterFactory.createReadSupporter( buffer , start , length , order );
  IntBuffer result = IntBuffer.allocate( size );
  for( int i = 0 ; i < size ; i++ ){
    result.put( wrapBuffer.getInt() );
  }
  result.position( 0 );
  return result;
}
 
Example 14
Source File: MockMxnetLibrary.java    From djl with Apache License 2.0 5 votes vote down vote up
/** {@inheritDoc} */
@Override
public int MXNDArrayGetShapeEx64(
        Pointer handle, IntBuffer out_dim, PointerByReference out_pdata) {
    if (functions.containsKey("MXNDArrayGetShapeEx64")) {
        return functions
                .get("MXNDArrayGetShapeEx64")
                .apply(new Object[] {handle, out_dim, out_pdata});
    }

    out_dim.put(0, 3);
    Pointer ptr = TestHelper.toPointer(new int[] {1, 2, 3});
    out_pdata.setValue(ptr);
    return 0;
}
 
Example 15
Source File: MappedIO.java    From java-core-learning-example with Apache License 2.0 5 votes vote down vote up
@Override
public void test() throws IOException {
    FileChannel fc = new RandomAccessFile(
            new File("data.txt"),"rw").getChannel();
    IntBuffer ib = fc.map(FileChannel.MapMode.READ_WRITE,
            0,fc.size()).asIntBuffer();
    ib.put(0);
    for (int i = 1; i < numOfUbuffInts; i++)
        ib.put(ib.get(i-1));
    fc.close();
}
 
Example 16
Source File: OffHeapHashMap.java    From offheap-store with Apache License 2.0 4 votes vote down vote up
@Override
public Map<K, V> removeAllWithHash(int hash) {
  freePendingTables();

  if (size == 0) {
    return Collections.emptyMap();
  }

  Map<K, V> removed = new HashMap<>();

  hashtable.position(indexFor(spread(hash)));

  int limit = reprobeLimit();

  for (int i = 0; i < limit; i++) {
    if (!hashtable.hasRemaining()) {
      hashtable.rewind();
    }

    IntBuffer entry = (IntBuffer) hashtable.slice().limit(ENTRY_SIZE);
    int entryPosition = hashtable.position();

    if (isTerminating(entry)) {
      return removed;
    } else if (isPresent(entry) && hash == entry.get(KEY_HASHCODE)) {
      @SuppressWarnings("unchecked")
      V removedValue = (V) storageEngine.readValue(readLong(entry, ENCODING));
      @SuppressWarnings("unchecked")
      K removedKey = (K) storageEngine.readKey(readLong(entry, ENCODING), hash);
      storageEngine.freeMapping(readLong(entry, ENCODING), entry.get(KEY_HASHCODE), true);

      removed.put(removedKey, removedValue);

      /*
       * TODO We might want to track the number of 'removed' slots in the
       * table, and rehash it if we reach some threshold to avoid lookup costs
       * staying artificially high when the table is relatively empty, but full
       * of 'removed' slots.  This situation should be relatively rare for
       * normal cache usage - but might be more common for more map like usage
       * patterns.
       *
       * The more severe versions of this pattern are now handled by the table
       * shrinking when the occupation drops below the shrink threshold, as
       * that will rehash the table.
       */
      entry.put(STATUS, STATUS_REMOVED);
      slotRemoved(entryPosition, entry);
    }
    hashtable.position(hashtable.position() + ENTRY_SIZE);
  }

  shrink();
  return removed;
}
 
Example 17
Source File: TrueTypeFont.java    From ForbiddenMagic with Do What The F*ck You Want To Public License 4 votes vote down vote up
public void destroy() {
	IntBuffer scratch = BufferUtils.createIntBuffer(1);
	scratch.put(0, fontTextureID);
	GL11.glBindTexture(GL11.GL_TEXTURE_2D, 0);
	GL11.glDeleteTextures(scratch);
}
 
Example 18
Source File: Bert.java    From easy-bert with MIT License 4 votes vote down vote up
private Inputs getInputs(final String[] sequences) {
    final String[][] tokens = tokenizer.tokenize(sequences);

    final IntBuffer inputIds = IntBuffer.allocate(sequences.length * model.maxSequenceLength);
    final IntBuffer inputMask = IntBuffer.allocate(sequences.length * model.maxSequenceLength);
    final IntBuffer segmentIds = IntBuffer.allocate(sequences.length * model.maxSequenceLength);

    /*
     * In BERT:
     * inputIds are the indexes in the vocabulary for each token in the sequence
     * inputMask is a binary mask that shows which inputIds have valid data in them
     * segmentIds are meant to distinguish paired sequences during training tasks. Here they're always 0 since we're only doing inference.
     */
    int instance = 1;
    for(final String[] token : tokens) {
        final int[] ids = tokenizer.convert(token);
        inputIds.put(startTokenId);
        inputMask.put(1);
        segmentIds.put(0);
        for(int i = 0; i < ids.length && i < model.maxSequenceLength - 2; i++) {
            inputIds.put(ids[i]);
            inputMask.put(1);
            segmentIds.put(0);
        }
        inputIds.put(separatorTokenId);
        inputMask.put(1);
        segmentIds.put(0);

        while(inputIds.position() < model.maxSequenceLength * instance) {
            inputIds.put(0);
            inputMask.put(0);
            segmentIds.put(0);
        }
        instance++;
    }

    inputIds.rewind();
    inputMask.rewind();
    segmentIds.rewind();

    return new Inputs(inputIds, inputMask, segmentIds, sequences.length);
}
 
Example 19
Source File: OffScreenFbo.java    From oreon-engine with GNU General Public License v3.0 4 votes vote down vote up
public OffScreenFbo(int width, int height, int samples) {
	
	GLTexture albedoAttachment = null;
	GLTexture worldPositionAttachment = null;
	GLTexture normalAttachment = null;
	GLTexture specularEmissionDiffuseSsaoBloomAttachment = null;
	GLTexture lightScatteringAttachment = null;
	GLTexture depthAttachment = null;
	
	albedoAttachment = new TextureImage2D(width, height, samples,
			ImageFormat.RGBA16FLOAT, SamplerFilter.Nearest, TextureWrapMode.ClampToEdge);
	worldPositionAttachment = new TextureImage2D(width, height, samples,
			ImageFormat.RGBA32FLOAT, SamplerFilter.Nearest, TextureWrapMode.ClampToEdge);
	normalAttachment = new TextureImage2D(width, height, samples,
			ImageFormat.RGBA16FLOAT, SamplerFilter.Nearest, TextureWrapMode.ClampToEdge);
	specularEmissionDiffuseSsaoBloomAttachment = new TextureImage2D(width, height, samples,
			ImageFormat.RGBA16FLOAT, SamplerFilter.Nearest, TextureWrapMode.ClampToEdge);
	lightScatteringAttachment = new TextureImage2D(width, height, samples,
			ImageFormat.RGBA16FLOAT, SamplerFilter.Nearest, TextureWrapMode.ClampToEdge);
	depthAttachment = new TextureImage2D(width, height, samples,
			ImageFormat.DEPTH32FLOAT, SamplerFilter.Nearest, TextureWrapMode.ClampToEdge);
		
	attachments.put(Attachment.COLOR, albedoAttachment);
	attachments.put(Attachment.POSITION, worldPositionAttachment);
	attachments.put(Attachment.NORMAL, normalAttachment);
	attachments.put(Attachment.SPECULAR_EMISSION_DIFFUSE_SSAO_BLOOM, specularEmissionDiffuseSsaoBloomAttachment);
	attachments.put(Attachment.LIGHT_SCATTERING, lightScatteringAttachment);
	attachments.put(Attachment.DEPTH, depthAttachment);
	
	IntBuffer drawBuffers = BufferUtil.createIntBuffer(5);
	drawBuffers.put(GL_COLOR_ATTACHMENT0);
	drawBuffers.put(GL_COLOR_ATTACHMENT1);
	drawBuffers.put(GL_COLOR_ATTACHMENT2);
	drawBuffers.put(GL_COLOR_ATTACHMENT3);
	drawBuffers.put(GL_COLOR_ATTACHMENT4);
	drawBuffers.flip();
	
	frameBuffer = new GLFramebuffer();
	frameBuffer.bind();
	
	frameBuffer.createColorTextureAttachment(albedoAttachment.getHandle(),0,(samples > 1));
	frameBuffer.createColorTextureAttachment(worldPositionAttachment.getHandle(),1,(samples > 1));
	frameBuffer.createColorTextureAttachment(normalAttachment.getHandle(),2,(samples > 1));
	frameBuffer.createColorTextureAttachment(specularEmissionDiffuseSsaoBloomAttachment.getHandle(),3,(samples > 1));
	frameBuffer.createColorTextureAttachment(lightScatteringAttachment.getHandle(),4,(samples > 1));
	frameBuffer.createDepthTextureAttachment(depthAttachment.getHandle(),(samples > 1));
	
	frameBuffer.setDrawBuffers(drawBuffers);
	frameBuffer.checkStatus();
	frameBuffer.unbind();
}
 
Example 20
Source File: AbstractTransportConnectionTestCases.java    From mongodb-async-driver with Apache License 2.0 4 votes vote down vote up
/**
 * Test method for {@link TransportConnection#shutdown} .
 *
 * @throws IOException
 *             On a failure connecting to the Mock MongoDB server.
 */
@Test
public void testShutdown() throws IOException {
    // Don't run on travis.
    assumeThat(getenv("TRAVIS"), not(is("true")));

    // From the BSON specification.
    final byte[] helloWorld = new byte[] { 0x16, 0x00, 0x00, 0x00, 0x02,
            (byte) 'h', (byte) 'e', (byte) 'l', (byte) 'l', (byte) 'o',
            0x00, 0x06, 0x00, 0x00, 0x00, (byte) 'w', (byte) 'o',
            (byte) 'r', (byte) 'l', (byte) 'd', 0x00, 0x00 };

    final ByteBuffer byteBuff = ByteBuffer.allocate(9 * 4);
    final IntBuffer buff = byteBuff.asIntBuffer();
    buff.put(0, (7 * 4) + 8 + helloWorld.length);
    buff.put(1, 0);
    buff.put(2, EndianUtils.swap(1));
    buff.put(3, EndianUtils.swap(Operation.REPLY.getCode()));
    buff.put(4, 0);
    buff.put(5, 0);
    buff.put(6, 0);
    buff.put(7, 0);
    buff.put(8, EndianUtils.swap(1));
    final ByteArrayOutputStream out = new ByteArrayOutputStream();
    out.write(byteBuff.array());
    out.write(helloWorld);
    ourServer.setReplies(Arrays.asList(out.toByteArray()));

    final MongoClientConfiguration config = new MongoClientConfiguration();
    config.setReadTimeout(100);
    connect(config);

    assertTrue("Should have connected to the server.",
            ourServer.waitForClient(TimeUnit.SECONDS.toMillis(10)));

    myTestConnection.shutdown(false);
    assertThat(myTestConnection.isAvailable(), is(false));
    myTestConnection.waitForClosed(10, TimeUnit.SECONDS);

    assertFalse(myTestConnection.isOpen());
}