Diable auto mock feature for Integration Tests

100 views
Skip to first unread message

Todd Nine

unread,
Apr 21, 2014, 2:43:34 PM4/21/14
to juk...@googlegroups.com
Hi Guys,

  We use Jukito extensively for our integration testing.  I'm running into an issue where our @Inject wiring is in correct.  Rather than Guice reporting an error, Jukito is creating a mock for it.  This results in strange test behavior that takes quite a bit to diagnose.  Rather than auto mock for our integration tests, we'd like to disable this and receive exceptions if Guice cannot inject our application correctly.  Is there a way to disable this feature for a test?


Thanks,
Todd

Stephan Classen

unread,
Apr 21, 2014, 3:26:20 PM4/21/14
to juk...@googlegroups.com
When you extend from TestModule instead of JukitoModule there is no auto mocking.
--
You received this message because you are subscribed to the Google Groups "Jukito" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jukito+un...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Todd Nine

unread,
Apr 22, 2014, 11:01:27 AM4/22/14
to juk...@googlegroups.com
Hi Stephan,
  I am extending TestModule, and I'm getting auto mock behavior.  Here is my Guice configuration for tests.


/**
 * Wrapper for configuring our guice test env
 */
public class TestGraphModule extends TestModule {

    @Override
    protected void configure() {
        install( new GraphModule() );
    }
}


I just install the system module, nothing more.  Here's the graph module code.



public class GraphModule extends AbstractModule {

    @Override
    protected void configure() {

        //configure collections and our core astyanax framework
        install( new CollectionModule() );

        //install our configuration
        install( new GuicyFigModule( GraphFig.class ) );

        bind( PostProcessObserver.class ).to( CollectionIndexObserver.class );

        bind( EdgeMetadataSerialization.class ).to( EdgeMetadataSerializationImpl.class );
        bind( NodeSerialization.class ).to( NodeSerializationImpl.class );


        bind( CassandraConfig.class ).to( CassandraConfigImpl.class );

        // create a guice factory for getting our collection manager
        install( new FactoryModuleBuilder().implement( GraphManager.class, GraphManagerImpl.class )
                                           .build( GraphManagerFactory.class ) );




        /**
         * bindings for shard allocations
         */

        bind( NodeShardAllocation.class ).to( NodeShardAllocationImpl.class );
        bind( NodeShardApproximation.class ).to( NodeShardApproximationImpl.class );
        bind( NodeShardCache.class ).to( NodeShardCacheImpl.class );

        /**
         * Bind our strategies based on their internal annotations.
         */

        bind( EdgeShardSerialization.class ).to( EdgeShardSerializationImpl.class );
        bind( EdgeShardCounterSerialization.class ).to( EdgeShardCounterSerializationImpl.class );


        /**
         * Graph event bus, will need to be refactored into it's own classes
         */

        // create a guice factory for getting our collection manager

        //local queue.  Need to replace with a real implementation
        bind( TimeoutQueue.class ).to( LocalTimeoutQueue.class );

        bind( AsyncProcessor.class ).annotatedWith( EdgeDelete.class ).to( AsyncProcessorImpl.class );
        bind( AsyncProcessor.class ).annotatedWith( NodeDelete.class ).to( AsyncProcessorImpl.class );
        bind( AsyncProcessor.class ).annotatedWith( EdgeWrite.class ).to( AsyncProcessorImpl.class );

        //Repair/cleanup classes
        bind( EdgeMetaRepair.class ).to( EdgeMetaRepairImpl.class );


        bind( EdgeDeleteRepair.class ).to( EdgeDeleteRepairImpl.class );


        /********
         * Migration bindings
         ********/


        //do multibindings for migrations
        Multibinder<Migration> migrationBinding = Multibinder.newSetBinder( binder(), Migration.class );
        migrationBinding.addBinding().to( Key.get( NodeSerialization.class ) );
        migrationBinding.addBinding().to( Key.get( EdgeMetadataSerialization.class ) );

        //bind each singleton to the multi set.  Otherwise we won't migrate properly
        migrationBinding.addBinding().to( Key.get( EdgeSerialization.class, PermanentStorage.class ) );
        migrationBinding.addBinding().to( Key.get( EdgeSerialization.class, CommitLog.class ) );

        migrationBinding.addBinding().to( Key.get( EdgeShardSerialization.class ) );
        migrationBinding.addBinding().to( Key.get( EdgeShardCounterSerialization.class ) );
    }


    /**
     * Our permanent serialization strategy
     */
    @Provides
    @Singleton
    @Inject
    @PermanentStorage
    public EdgeSerialization permanentStorageSerialization( final NodeShardCache cache, final Keyspace keyspace,
                                                            final CassandraConfig cassandraConfig,
                                                            final GraphFig graphFig ) {

        final EdgeShardStrategy sizeBasedStrategy = new SizebasedEdgeShardStrategy( cache );

        final EdgeSerializationImpl edgeSerialization =
                new EdgeSerializationImpl( keyspace, cassandraConfig, graphFig, sizeBasedStrategy );


        return edgeSerialization;
    }


    /**
     * The commit log strategy for fast writes
     */
    @Provides
    @Singleton
    @Inject
    @CommitLog
    public EdgeSerialization commitlogStorageSerialization( final NodeShardCache cache, final Keyspace keyspace,
                                                            final CassandraConfig cassandraConfig,
                                                            final GraphFig graphFig ) {

        final EdgeShardStrategy sizeBasedStrategy = new TimebasedEdgeShardStrategy( cache );

        final EdgeSerializationImpl edgeSerialization =
                new EdgeSerializationImpl( keyspace, cassandraConfig, graphFig, sizeBasedStrategy );


        return edgeSerialization;
    }
}


--
You received this message because you are subscribed to a topic in the Google Groups "Jukito" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/jukito/Sf1mfY5ydEg/unsubscribe.
To unsubscribe from this group and all its topics, send an email to jukito+un...@googlegroups.com.

Stephan Classen

unread,
Apr 22, 2014, 2:42:43 PM4/22/14
to juk...@googlegroups.com
Hi Todd

The injection point where you expect an exception but get a mock. Does it request an interface or a class.
Guice can create bindings on the fly for classes which have a default constructor or a constructor annotated with @Inject.
you can call binder().requireExplicitBindings() in any module to prevent Guice from doing so.

Todd Nine

unread,
Apr 22, 2014, 3:02:27 PM4/22/14
to juk...@googlegroups.com
Hi Stephan,
  It requires an interface.  Here is a link to the file that's causing issues.


Note that there are 2 implementations both with annotations in the Guice file.  However, when running it in a test, I get a Mockito mock instance, instead of an error that Guice could not determine the type to inject.


Stephan Classen

unread,
Apr 22, 2014, 3:06:34 PM4/22/14
to juk...@googlegroups.com
Since it is all on github
could you point me to the test so I can try to reproduce the behavior you see.

Todd Nine

unread,
Apr 22, 2014, 3:20:51 PM4/22/14
to juk...@googlegroups.com

Stephan Classen

unread,
Apr 22, 2014, 6:24:05 PM4/22/14
to juk...@googlegroups.com
Ok, found it :)

You are using the following annotation to define the modules to install:
@UseModules({ TestGraphModule.class })

This creates a JukitoModule and installs the TestGraphModule.
See https://github.com/ArcBees/Jukito/blob/master/jukito/src/main/java/org/jukito/JukitoRunner.java#L167

If you want to have a TestModule there is currently no way to circumvent the "public static class Xxx extends TestModule"

Though it would be easy to extend the @UseModules to pass a boolean if auto mock should be used or not (default would be true to keep the current behavior).
So feel free to submit a pull request :)
Reply all
Reply to author
Forward
0 new messages