Commit b0d8bb90 by Ballistar13
parents 55febc44 9ec7ad37
package org.apache.hadoop.metadata;
import com.google.inject.Guice;
import com.google.inject.Injector;
import com.google.inject.Module;
public abstract class GuiceEnabledTestBase {
/*
* Guice.createInjector() takes your Modules, and returns a new Injector
* instance. Most applications will call this method exactly once, in their
* main() method.
*/
public final Injector injector;
GuiceEnabledTestBase() {
injector = Guice.createInjector();
}
GuiceEnabledTestBase(Module... modules) {
injector = Guice.createInjector(modules);
}
}
package org.apache.hadoop.metadata;
public abstract class RepositoryModuleBaseTest extends GuiceEnabledTestBase {
public RepositoryModuleBaseTest() {
super(new RepositoryMetadataModule());
}
}
package org.apache.hadoop.metadata; package org.apache.hadoop.metadata;
import javax.inject.Inject;
import junit.framework.Assert; import junit.framework.Assert;
import org.apache.hadoop.metadata.repository.graph.GraphService; import org.apache.hadoop.metadata.repository.graph.GraphService;
import org.testng.annotations.AfterClass; import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass; import org.testng.annotations.BeforeClass;
import org.testng.annotations.Guice;
import org.testng.annotations.Test; import org.testng.annotations.Test;
/** /**
* Unit test for Guice injector service loading * Unit test for Guice injector service loading
*
* Uses TestNG's Guice annotation to load the necessary modules and inject the
* objects from Guice
*/ */
public class RepositoryServiceLoadingTest extends GuiceEnabledTestBase { @Guice(modules = RepositoryMetadataModule.class)
public class RepositoryServiceLoadingTest {
public RepositoryServiceLoadingTest() { @Inject
super(new RepositoryMetadataModule()); GraphService gs;
}
@BeforeClass @BeforeClass
public void setUp() throws Exception { public void setUp() throws Exception {
...@@ -26,10 +32,6 @@ public class RepositoryServiceLoadingTest extends GuiceEnabledTestBase { ...@@ -26,10 +32,6 @@ public class RepositoryServiceLoadingTest extends GuiceEnabledTestBase {
@Test @Test
public void testGetGraphService() throws Exception { public void testGetGraphService() throws Exception {
/*
* Now that we've got the injector, we can build objects.
*/
GraphService gs = injector.getInstance(GraphService.class);
Assert.assertNotNull(gs); Assert.assertNotNull(gs);
} }
} }
...@@ -2,11 +2,14 @@ package org.apache.hadoop.metadata.services; ...@@ -2,11 +2,14 @@ package org.apache.hadoop.metadata.services;
import java.util.List; import java.util.List;
import javax.inject.Inject;
import org.apache.hadoop.metadata.ITypedReferenceableInstance; import org.apache.hadoop.metadata.ITypedReferenceableInstance;
import org.apache.hadoop.metadata.MetadataException; import org.apache.hadoop.metadata.MetadataException;
import org.apache.hadoop.metadata.Referenceable; import org.apache.hadoop.metadata.Referenceable;
import org.apache.hadoop.metadata.RepositoryModuleBaseTest; import org.apache.hadoop.metadata.RepositoryMetadataModule;
import org.apache.hadoop.metadata.repository.graph.GraphBackedMetadataRepository; import org.apache.hadoop.metadata.repository.graph.GraphBackedMetadataRepository;
import org.apache.hadoop.metadata.repository.graph.GraphUtils;
import org.apache.hadoop.metadata.repository.graph.TitanGraphService; import org.apache.hadoop.metadata.repository.graph.TitanGraphService;
import org.apache.hadoop.metadata.storage.IRepository; import org.apache.hadoop.metadata.storage.IRepository;
import org.apache.hadoop.metadata.storage.memory.MemRepository; import org.apache.hadoop.metadata.storage.memory.MemRepository;
...@@ -20,10 +23,10 @@ import org.apache.hadoop.metadata.types.Multiplicity; ...@@ -20,10 +23,10 @@ import org.apache.hadoop.metadata.types.Multiplicity;
import org.apache.hadoop.metadata.types.StructTypeDefinition; import org.apache.hadoop.metadata.types.StructTypeDefinition;
import org.apache.hadoop.metadata.types.TraitType; import org.apache.hadoop.metadata.types.TraitType;
import org.apache.hadoop.metadata.types.TypeSystem; import org.apache.hadoop.metadata.types.TypeSystem;
import org.apache.hadoop.metadata.repository.graph.GraphUtils;
import org.testng.Assert; import org.testng.Assert;
import org.testng.annotations.AfterClass; import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass; import org.testng.annotations.BeforeClass;
import org.testng.annotations.Guice;
import org.testng.annotations.Test; import org.testng.annotations.Test;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
...@@ -32,23 +35,32 @@ import com.tinkerpop.blueprints.Direction; ...@@ -32,23 +35,32 @@ import com.tinkerpop.blueprints.Direction;
import com.tinkerpop.blueprints.Edge; import com.tinkerpop.blueprints.Edge;
import com.tinkerpop.blueprints.Vertex; import com.tinkerpop.blueprints.Vertex;
/**
* GraphBackedMetadataRepository test
*
* Guice loads the dependencies and injects the necessary objects
*
*/
@Test (enabled = false) @Test (enabled = false)
public class GraphBackedMetadataRepositoryTest extends RepositoryModuleBaseTest { @Guice(modules = RepositoryMetadataModule.class)
public class GraphBackedMetadataRepositoryTest {
private static final String ENTITY_TYPE = "hive-table"; private static final String ENTITY_TYPE = "hive-table";
private TitanGraphService titanGraphService; @Inject
private GraphBackedMetadataRepository repositoryService; TitanGraphService titanGraphService;
@Inject
GraphBackedMetadataRepository repositoryService;
private IRepository repo; private IRepository repo;
private TypeSystem ts; private TypeSystem ts;
private String guid; private String guid;
@BeforeClass @BeforeClass
public void setUp() throws Exception { public void setUp() throws Exception {
titanGraphService = super.injector.getInstance(TitanGraphService.class); // start the injected graph service
titanGraphService.start(); titanGraphService.start();
// start the injected repository service
repositoryService = super.injector.getInstance(GraphBackedMetadataRepository.class);
repositoryService.start(); repositoryService.start();
ts = TypeSystem.getInstance(); ts = TypeSystem.getInstance();
......
package org.apache.hadoop.metadata.services; package org.apache.hadoop.metadata.services;
import org.apache.hadoop.metadata.RepositoryModuleBaseTest; import javax.inject.Inject;
import org.apache.hadoop.metadata.RepositoryMetadataModule;
import org.apache.hadoop.metadata.repository.graph.TitanGraphService; import org.apache.hadoop.metadata.repository.graph.TitanGraphService;
import org.testng.Assert; import org.testng.Assert;
import org.testng.annotations.AfterClass; import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass; import org.testng.annotations.BeforeClass;
import org.testng.annotations.Guice;
import org.testng.annotations.Test; import org.testng.annotations.Test;
/** /**
* Unit test for TitanGraphService. * Unit test for TitanGraphService.
*/ */
public class TitanGraphServiceTest extends RepositoryModuleBaseTest { @Guice(modules = RepositoryMetadataModule.class)
public class TitanGraphServiceTest {
private TitanGraphService titanGraphService; @Inject
TitanGraphService titanGraphService;
@BeforeClass @BeforeClass
public void setUp() throws Exception { public void setUp() throws Exception {
titanGraphService = super.injector.getInstance(TitanGraphService.class);
//titanGraphService = new TitanGraphService();
titanGraphService.start(); titanGraphService.start();
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment