Java源码示例:org.alfresco.repo.index.shard.ShardMethodEnum
示例1
protected AbstractTracker(Properties p, SOLRAPIClient client, String coreName, InformationServer informationServer,Type type)
{
this.props = p;
this.client = client;
this.coreName = coreName;
this.infoSrv = informationServer;
storeRef = new StoreRef(p.getProperty("alfresco.stores", "workspace://SpacesStore"));
batchCount = Integer.parseInt(p.getProperty("alfresco.batch.count", "5000"));
maxLiveSearchers = Integer.parseInt(p.getProperty("alfresco.maxLiveSearchers", "2"));
shardCount = Integer.parseInt(p.getProperty("shard.count", "1"));
shardInstance = Integer.parseInt(p.getProperty("shard.instance", "0"));
shardMethod = ShardMethodEnum.getShardMethod(p.getProperty("shard.method", DB_ID.name()));
shardTemplate = p.getProperty("alfresco.template", "");
transformContent = Boolean.parseBoolean(p.getProperty("alfresco.index.transformContent", "true"));
this.trackerStats = this.infoSrv.getTrackerStats();
this.type = type;
this.trackerId = type + "@" + hashCode();
}
示例2
/** Check that a DB_ID_RANGE router can be created. */
@Test
public void testDBIDRANGEWithShardRangeKey()
{
Properties mockProperties = mock(Properties.class);
when(mockProperties.containsKey(SHARD_RANGE_KEY)).thenReturn(true);
when(mockProperties.getProperty(SHARD_RANGE_KEY)).thenReturn("100000000-150000000");
// Call the method under test.
DocRouter docRouter = DocRouterFactory.getRouter(mockProperties, ShardMethodEnum.DB_ID_RANGE);
assertTrue("Expected to get a DBIDRangeRouter.", docRouter instanceof DBIDRangeRouter);
DBIDRangeRouter dbidRangeRouter = (DBIDRangeRouter) docRouter;
assertEquals("Unexpected start of range.", dbidRangeRouter.getStartRange(), 100000000L);
assertEquals("Unexpected end of range.", dbidRangeRouter.getEndRange(), 150000000L);
}
示例3
@Test
public void matchIsCaseInsensitive()
{
Assert.assertEquals(ShardMethodEnum.MOD_ACL_ID, ShardMethodEnum.getShardMethod("MoD_aCl_id"));
Assert.assertEquals(ShardMethodEnum.DB_ID_RANGE, ShardMethodEnum.getShardMethod("db_id_range"));
Assert.assertEquals(ShardMethodEnum.ACL_ID, ShardMethodEnum.getShardMethod("Acl_Id"));
Assert.assertEquals(ShardMethodEnum.DB_ID, ShardMethodEnum.getShardMethod("Db_Id"));
Assert.assertEquals(ShardMethodEnum.EXPLICIT_ID, ShardMethodEnum.getShardMethod("Explicit_Id"));
Assert.assertEquals(ShardMethodEnum.EXPLICIT_ID, ShardMethodEnum.getShardMethod("explicit_ID_fallback_DBID"));
Assert.assertEquals(ShardMethodEnum.LAST_REGISTERED_INDEXING_SHARD, ShardMethodEnum.getShardMethod("LRIS"));
Assert.assertEquals(ShardMethodEnum.LAST_REGISTERED_INDEXING_SHARD, ShardMethodEnum.getShardMethod("LAST_REGISTERED_INDEXING_SHARD"));
Assert.assertEquals(ShardMethodEnum.DATE, ShardMethodEnum.getShardMethod("datE"));
Assert.assertEquals(ShardMethodEnum.PROPERTY, ShardMethodEnum.getShardMethod("PropertY"));
Assert.assertEquals(ShardMethodEnum.UNKOWN, ShardMethodEnum.getShardMethod("Unknown"));
}
示例4
protected static Properties getShardMethod()
{
Random random = random();
List<ShardMethodEnum> methods = new ArrayList<>();
methods.add(ShardMethodEnum.ACL_ID);
methods.add(ShardMethodEnum.MOD_ACL_ID);
Collections.shuffle(methods, random);
Properties prop = new Properties();
prop.put("shard.method", methods.get(0).toString());
return prop;
}
示例5
protected static Properties getShardMethod()
{
Properties prop = new Properties();
prop.put("shard.method", ShardMethodEnum.DATE.toString());
prop.put("shard.date.grouping", "3");
return prop;
}
示例6
@Before
public void setUp()
{
MockitoAnnotations.initMocks(this);
Properties properties = new Properties();
properties.put("shard.range", "200-20000");
router = DocRouterFactory.getRouter(properties, ShardMethodEnum.DB_ID_RANGE);
}
示例7
protected static Properties getProperties()
{
Properties prop = new Properties();
prop.put("shard.method", ShardMethodEnum.PROPERTY.toString());
prop.put("shard.regex", "^[A-Za-z0-9._%+-][email protected]([A-Za-z0-9.-]+\\.[A-Za-z]{2,6})$");
prop.put(SHARD_KEY_KEY, ContentModel.PROP_EMAIL.toString());
return prop;
}
示例8
protected static Properties getShardMethod()
{
Properties prop = new Properties();
prop.put("shard.method", ShardMethodEnum.DATE.toString());
prop.put("shard.date.grouping", "6");
return prop;
}
示例9
protected static Properties getProperties()
{
Properties prop = new Properties();
prop.put("shard.method", ShardMethodEnum.EXPLICIT_ID.toString());
//Normally this would be used by the Solr client which will automatically add the property to the node.shardPropertyValue
//For testing this doesn't work like that so I setShardPropertyValue explicitly above.
prop.put(SHARD_KEY_KEY, ContentModel.PROP_SKYPE.toString());
return prop;
}
示例10
/** Check that an exception is raised if the range information is missing. */
@Test(expected = AlfrescoRuntimeException.class)
public void testDBIDRANGEWithoutShardRangeKey()
{
Properties mockProperties = mock(Properties.class);
DocRouterFactory.getRouter(mockProperties, ShardMethodEnum.DB_ID_RANGE);
}
示例11
private static Properties getShardMethod()
{
Properties prop = new Properties();
prop.put("shard.method", ShardMethodEnum.DATE.toString());
prop.put("shard.date.grouping", "1");
return prop;
}
示例12
@Test
public void testTypeACLLegacy()
{
Assert.assertEquals(ShardMethodEnum.MOD_ACL_ID, ShardMethodEnum.getShardMethod("MOD_ACL_ID"));
}
示例13
@Test
public void testDBIDRange()
{
Assert.assertEquals(ShardMethodEnum.DB_ID_RANGE, ShardMethodEnum.getShardMethod("DB_ID_RANGE"));
}
示例14
@Test
public void testTypeACLBasedOnMurmurHash()
{
Assert.assertEquals(ShardMethodEnum.ACL_ID, ShardMethodEnum.getShardMethod("ACL_ID"));
}
示例15
@Test
public void testTypeDBID()
{
Assert.assertEquals(ShardMethodEnum.DB_ID, ShardMethodEnum.getShardMethod("DB_ID"));
}
示例16
@Test
public void testTypeEXPLICITID()
{
Assert.assertEquals(ShardMethodEnum.EXPLICIT_ID, ShardMethodEnum.getShardMethod("EXPLICIT_ID"));
Assert.assertEquals(ShardMethodEnum.EXPLICIT_ID, ShardMethodEnum.getShardMethod("EXPLICIT_ID_FALLBACK_DBID"));
}
示例17
@Test
public void testTypeLRIS()
{
Assert.assertEquals(ShardMethodEnum.LAST_REGISTERED_INDEXING_SHARD, ShardMethodEnum.getShardMethod("LRIS"));
Assert.assertEquals(ShardMethodEnum.LAST_REGISTERED_INDEXING_SHARD, ShardMethodEnum.getShardMethod("LAST_REGISTERED_INDEXING_SHARD"));
}
示例18
@Test
public void testTypeEXPLICIT_ID_FALLBACK_LRIS()
{
Assert.assertEquals(ShardMethodEnum.EXPLICIT_ID_FALLBACK_LRIS, ShardMethodEnum.getShardMethod("EXPLICIT_ID_FALLBACK_LRIS"));
}
示例19
@Test
public void testTypeDateTimeStamp()
{
Assert.assertEquals(ShardMethodEnum.DATE, ShardMethodEnum.getShardMethod("DATE"));
}
示例20
@Test
public void testTypeProperty()
{
Assert.assertEquals(ShardMethodEnum.PROPERTY, ShardMethodEnum.getShardMethod("PROPERTY"));
}
示例21
@Test
public void testUnknown()
{
Assert.assertEquals(ShardMethodEnum.UNKOWN, ShardMethodEnum.getShardMethod("UNKOWN"));
Assert.assertEquals(ShardMethodEnum.UNKOWN, ShardMethodEnum.getShardMethod("Some else unknown value"));
}
示例22
@Test
public void testNull()
{
Assert.assertEquals(ShardMethodEnum.UNKOWN, ShardMethodEnum.getShardMethod(null));
}
示例23
@Test
public void testEmpty()
{
Assert.assertEquals(ShardMethodEnum.UNKOWN, ShardMethodEnum.getShardMethod(""));
}
示例24
public static DocRouter getRouter(Properties properties, ShardMethodEnum method) {
switch(method) {
case DB_ID:
LOGGER.info("Sharding via DB_ID");
return new DBIDRouter();
case DB_ID_RANGE:
if(!properties.containsKey(SHARD_RANGE_KEY))
{
throw new AlfrescoRuntimeException("DB_ID_RANGE sharding requires the " + SHARD_RANGE_KEY + " property to be set.");
}
LOGGER.info("Sharding via DB_ID_RANGE");
String[] pair = properties.getProperty(SHARD_RANGE_KEY).split("-");
long start = Long.parseLong(pair[0]);
long end = Long.parseLong(pair[1]);
return new DBIDRangeRouter(start, end);
case ACL_ID:
LOGGER.info("Sharding via ACL_ID");
return new ACLIDMurmurRouter();
case MOD_ACL_ID:
LOGGER.info("Sharding via MOD_ACL_ID");
return new ACLIDModRouter();
case DATE:
LOGGER.info("Sharding via DATE");
return new DateMonthRouter(properties.getProperty(SHARD_DATE_GROUPING_KEY, "1"));
case PROPERTY:
LOGGER.info("Sharding via PROPERTY");
return new PropertyRouter(properties.getProperty(SHARD_REGEX_KEY, ""));
case LAST_REGISTERED_INDEXING_SHARD:
LOGGER.warn("Sharding via LAST_REGISTERED_INDEXING_SHARD: Note this is available at the moment as an Early Access/preview feature!");
return new ExplicitShardIdWithStaticPropertyRouter();
case EXPLICIT_ID_FALLBACK_LRIS:
LOGGER.warn("Sharding via EXPLICIT_ID_FALLBACK_LRIS: Note the LRIS Router (which is part of this composite router) is available at the moment as an Early Access/preview feature!");
return new DocRouterWithFallback(
new ExplicitShardIdWithDynamicPropertyRouter(false),
new ExplicitShardIdWithStaticPropertyRouter());
case EXPLICIT_ID:
LOGGER.info("Sharding via EXPLICIT_ID");
return new DocRouterWithFallback(
new ExplicitShardIdWithDynamicPropertyRouter(false),
new DBIDRouter());
default:
LOGGER.warn("WARNING! Unknown/unsupported sharding method ({}). System will fallback to DB_ID", method);
return new DBIDRouter();
}
}
示例25
@Before
public void setUp()
{
router = DocRouterFactory.getRouter(new Properties(), ShardMethodEnum.ACL_ID);
}
示例26
@Before
public void setUp()
{
router = DocRouterFactory.getRouter(new Properties(), ShardMethodEnum.EXPLICIT_ID);
}
示例27
@Before
public void setUp()
{
router = DocRouterFactory.getRouter(new Properties(), ShardMethodEnum.MOD_ACL_ID);
}
示例28
@Before
public void setUp()
{
router = DocRouterFactory.getRouter(new Properties(), ShardMethodEnum.DB_ID);
}
示例29
protected static Properties getProperties()
{
Properties prop = new Properties();
prop.put("shard.method", ShardMethodEnum.LAST_REGISTERED_INDEXING_SHARD.toString());
return prop;
}
示例30
@Before
public void setUp()
{
router = DocRouterFactory.getRouter(new Properties(), ShardMethodEnum.EXPLICIT_ID_FALLBACK_LRIS);
}