Commit b6d4e094 by TJBChris
parents 46667712 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;
import javax.inject.Inject;
import junit.framework.Assert;
import org.apache.hadoop.metadata.repository.graph.GraphService;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Guice;
import org.testng.annotations.Test;
/**
* 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() {
super(new RepositoryMetadataModule());
}
@Inject
GraphService gs;
@BeforeClass
public void setUp() throws Exception {
......@@ -26,10 +32,6 @@ public class RepositoryServiceLoadingTest extends GuiceEnabledTestBase {
@Test
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);
}
}
......@@ -2,11 +2,14 @@ package org.apache.hadoop.metadata.services;
import java.util.List;
import javax.inject.Inject;
import org.apache.hadoop.metadata.ITypedReferenceableInstance;
import org.apache.hadoop.metadata.MetadataException;
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.GraphUtils;
import org.apache.hadoop.metadata.repository.graph.TitanGraphService;
import org.apache.hadoop.metadata.storage.IRepository;
import org.apache.hadoop.metadata.storage.memory.MemRepository;
......@@ -20,10 +23,10 @@ import org.apache.hadoop.metadata.types.Multiplicity;
import org.apache.hadoop.metadata.types.StructTypeDefinition;
import org.apache.hadoop.metadata.types.TraitType;
import org.apache.hadoop.metadata.types.TypeSystem;
import org.apache.hadoop.metadata.repository.graph.GraphUtils;
import org.testng.Assert;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Guice;
import org.testng.annotations.Test;
import com.google.common.collect.ImmutableList;
......@@ -32,23 +35,32 @@ import com.tinkerpop.blueprints.Direction;
import com.tinkerpop.blueprints.Edge;
import com.tinkerpop.blueprints.Vertex;
/**
* GraphBackedMetadataRepository test
*
* Guice loads the dependencies and injects the necessary objects
*
*/
@Test (enabled = false)
public class GraphBackedMetadataRepositoryTest extends RepositoryModuleBaseTest {
@Guice(modules = RepositoryMetadataModule.class)
public class GraphBackedMetadataRepositoryTest {
private static final String ENTITY_TYPE = "hive-table";
private TitanGraphService titanGraphService;
private GraphBackedMetadataRepository repositoryService;
@Inject
TitanGraphService titanGraphService;
@Inject
GraphBackedMetadataRepository repositoryService;
private IRepository repo;
private TypeSystem ts;
private String guid;
@BeforeClass
public void setUp() throws Exception {
titanGraphService = super.injector.getInstance(TitanGraphService.class);
// start the injected graph service
titanGraphService.start();
repositoryService = super.injector.getInstance(GraphBackedMetadataRepository.class);
// start the injected repository service
repositoryService.start();
ts = TypeSystem.getInstance();
......
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.testng.Assert;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Guice;
import org.testng.annotations.Test;
/**
* Unit test for TitanGraphService.
*/
public class TitanGraphServiceTest extends RepositoryModuleBaseTest {
@Guice(modules = RepositoryMetadataModule.class)
public class TitanGraphServiceTest {
private TitanGraphService titanGraphService;
@Inject
TitanGraphService titanGraphService;
@BeforeClass
public void setUp() throws Exception {
titanGraphService = super.injector.getInstance(TitanGraphService.class);
//titanGraphService = new TitanGraphService();
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