[ 
https://issues.apache.org/jira/browse/RYA-174?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15602657#comment-15602657
 ] 

ASF GitHub Bot commented on RYA-174:
------------------------------------

Github user amihalik commented on a diff in the pull request:

    https://github.com/apache/incubator-rya/pull/118#discussion_r84739864
  
    --- Diff: 
dao/mongodb.rya/src/main/java/org/apache/rya/mongodb/MockMongoFactory.java ---
    @@ -0,0 +1,97 @@
    +/*
    + * 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.rya.mongodb;
    +
    +import java.io.IOException;
    +import java.net.ServerSocket;
    +import java.net.UnknownHostException;
    +
    +import org.slf4j.Logger;
    +import org.slf4j.LoggerFactory;
    +
    +import com.mongodb.MongoClient;
    +import com.mongodb.MongoException;
    +import com.mongodb.ServerAddress;
    +
    +import de.flapdoodle.embed.mongo.Command;
    +import de.flapdoodle.embed.mongo.MongodExecutable;
    +import de.flapdoodle.embed.mongo.MongodProcess;
    +import de.flapdoodle.embed.mongo.MongodStarter;
    +import de.flapdoodle.embed.mongo.config.IMongodConfig;
    +import de.flapdoodle.embed.mongo.config.MongodConfigBuilder;
    +import de.flapdoodle.embed.mongo.config.Net;
    +import de.flapdoodle.embed.mongo.config.RuntimeConfigBuilder;
    +import de.flapdoodle.embed.mongo.distribution.IFeatureAwareVersion;
    +import de.flapdoodle.embed.mongo.distribution.Version;
    +
    +public class MockMongoFactory {
    +    private static Logger logger = 
LoggerFactory.getLogger(MockMongoFactory.class.getName());
    +
    +    public static MockMongoFactory newFactory() throws IOException {
    +        return MockMongoFactory.with(Version.Main.PRODUCTION);
    +    }
    +    
    +    public static MockMongoFactory with(final IFeatureAwareVersion 
version) throws IOException {
    +        return new MockMongoFactory(version);
    +    }
    +
    +    private final MongodExecutable mongodExecutable;
    +    private final MongodProcess mongodProcess;
    +
    +    /**
    +     * Create the testing utility using the specified version of MongoDB.
    +     * 
    +     * @param version
    +     *            version of MongoDB.
    +     */
    +    private MockMongoFactory(final IFeatureAwareVersion version) throws 
IOException {
    +        final MongodStarter runtime = MongodStarter.getInstance(new 
RuntimeConfigBuilder().defaultsWithLogger(Command.MongoD, logger).build());
    +        mongodExecutable = runtime.prepare(newMongodConfig(version));
    +        mongodProcess = mongodExecutable.start();
    +    }
    +
    +    private IMongodConfig newMongodConfig(final IFeatureAwareVersion 
version) throws UnknownHostException, IOException {
    +        Net net = new Net(findRandomOpenPortOnAllLocalInterfaces(), false);
    +        return new MongodConfigBuilder().version(version).net(net).build();
    +    }
    +
    +    private int findRandomOpenPortOnAllLocalInterfaces() throws 
IOException {
    +        try (ServerSocket socket = new ServerSocket(0);) {
    +            return socket.getLocalPort();
    +        }
    +    }
    +
    +    /**
    +     * Creates a new Mongo connection.
    +     * 
    +     * @throws MongoException
    +     * @throws UnknownHostException
    +     */
    +    public MongoClient newMongo() throws UnknownHostException, 
MongoException {
    --- End diff --
    
    Done.


> Embedded Mongo tries to bind to busy ports
> ------------------------------------------
>
>                 Key: RYA-174
>                 URL: https://issues.apache.org/jira/browse/RYA-174
>             Project: Rya
>          Issue Type: Bug
>            Reporter: Aaron Mihalik
>            Assignee: Aaron Mihalik
>             Fix For: 3.2.10
>
>
> There are a couple mongo tests that fail while building on builds.a.o.  It 
> looks like Embedded Mongo will try to bind to ports that are already in use.
> https://builds.apache.org/view/Incubator%20Projects/job/incubator-rya-master/org.apache.rya$rya.indexing/31/testReport/junit/mvm.rya.indexing.mongo/MongoGeoIndexerSfTest/testIntersectsLine/
> https://builds.apache.org/view/Incubator%20Projects/job/incubator-rya-master/org.apache.rya$rya.indexing/31/testReport/junit/mvm.rya.indexing.mongo/MongoTemporalIndexerTest/testQueryInstantHasBeginningInterval/



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to