public MongoNodeGroupStore(Config config) { super(config); setTableName(JobQueueUtils.NODE_GROUP_STORE); // create table DBCollection dbCollection = template.getCollection(); List<DBObject> indexInfo = dbCollection.getIndexInfo(); // create index if not exist if (CollectionUtils.sizeOf(indexInfo) <= 1) { template.ensureIndex("idx_nodeType_name", "nodeType,name", true, true); } }
public MongoNodeGroupStore(Config config) { super(config); setTableName(JobQueueUtils.NODE_GROUP_STORE); // create table DBCollection dbCollection = template.getCollection(); List<DBObject> indexInfo = dbCollection.getIndexInfo(); // create index if not exist if (CollectionUtils.sizeOf(indexInfo) <= 1) { template.ensureIndex("idx_nodeType_name", "nodeType,name", true, true); } }
@Override public boolean createQueue(String jobClientNodeGroup) { String tableName = JobQueueUtils.getFeedbackQueueName(jobClientNodeGroup); DBCollection dbCollection = template.getCollection(tableName); List<DBObject> indexInfo = dbCollection.getIndexInfo(); // create index if not exist if (CollectionUtils.sizeOf(indexInfo) <= 1) { template.ensureIndex(tableName, "idx_gmtCreated", "gmtCreated"); LOGGER.info("create queue " + tableName); } return true; }
@Override public boolean createQueue(String jobClientNodeGroup) { String tableName = JobQueueUtils.getFeedbackQueueName(jobClientNodeGroup); DBCollection dbCollection = template.getCollection(tableName); List<DBObject> indexInfo = dbCollection.getIndexInfo(); // create index if not exist if (CollectionUtils.sizeOf(indexInfo) <= 1) { template.ensureIndex(tableName, "idx_gmtCreated", "gmtCreated"); LOGGER.info("create queue " + tableName); } return true; }
public MongoJobLogger(Config config) { super(config); setTableName("lts_job_log_po"); // create table DBCollection dbCollection = template.getCollection(); List<DBObject> indexInfo = dbCollection.getIndexInfo(); // create index if not exist if (CollectionUtils.sizeOf(indexInfo) <= 1) { template.ensureIndex("idx_logTime", "logTime"); template.ensureIndex("idx_taskId_taskTrackerNodeGroup", "taskId,taskTrackerNodeGroup"); template.ensureIndex("idx_realTaskId_taskTrackerNodeGroup", "realTaskId, taskTrackerNodeGroup"); } }
public MongoJobLogger(Config config) { super(config); setTableName("lts_job_log_po"); // create table DBCollection dbCollection = template.getCollection(); List<DBObject> indexInfo = dbCollection.getIndexInfo(); // create index if not exist if (CollectionUtils.sizeOf(indexInfo) <= 1) { template.ensureIndex("idx_logTime", "logTime"); template.ensureIndex("idx_taskId_taskTrackerNodeGroup", "taskId,taskTrackerNodeGroup"); template.ensureIndex("idx_realTaskId_taskTrackerNodeGroup", "realTaskId, taskTrackerNodeGroup"); } }
private void findPartialIndex(final BasicDBObject expected) { List<DBObject> indexInfo = getDs().getCollection(IndexedClass.class) .getIndexInfo(); for (DBObject dbObject : indexInfo) { if (!dbObject.get("name").equals("_id_")) { Assert.assertEquals(expected, dbObject.get("partialFilterExpression")); } } }
@Test public void testParamEntity() throws Exception { final MappedClass mc = getMorphia().getMapper().getMappedClass(A.class); assertNotNull(mc); assertEquals(1, mc.getAnnotations(Indexes.class).size()); getDs().ensureIndexes(A.class); final DBCollection coll = getDs().getCollection(A.class); assertEquals("indexes found: coll.getIndexInfo()" + coll.getIndexInfo(), 3, coll.getIndexInfo().size()); }
@Test public void testOldStyleIndexing() { getMorphia().map(OldStyleIndexing.class); getDb().dropDatabase(); getAds().ensureIndexes(); testIndex(getAds().getCollection(OldStyleIndexing.class).getIndexInfo(), new BasicDBObject("field", 1), new BasicDBObject("field2", -1), new BasicDBObject("f3", 1)); }
@Test public void testCanCreate2dSphereIndexes() { // given getMorphia().map(Place.class); // when getDs().ensureIndexes(); // then List<DBObject> indexInfo = getDs().getCollection(Place.class).getIndexInfo(); assertThat(indexInfo.size(), is(2)); assertThat(indexInfo, hasIndexNamed("location_2dsphere")); }
@Test public void testNamedIndexEntity() throws Exception { getDs().ensureIndexes(); assertThat(getDs().getCollection(NamedIndexOnValue.class).getIndexInfo(), hasIndexNamed("value_ascending")); }
@Test public void testIndexedEntity() throws Exception { getDs().ensureIndexes(); assertThat(getDs().getCollection(IndexOnValue.class).getIndexInfo(), hasIndexNamed("value_1")); getDs().save(new IndexOnValue()); getDs().ensureIndexes(); assertThat(getDs().getCollection(IndexOnValue.class).getIndexInfo(), hasIndexNamed("value_1")); }
@Test public void testIndexes() { final MappedClass mc = getMorphia().getMapper().addMappedClass(Ad2.class); assertThat(getDb().getCollection(mc.getCollectionName()).getIndexInfo(), doesNotHaveIndexNamed("active_1_lastMod_-1")); getDs().ensureIndexes(Ad2.class); assertThat(getDb().getCollection(mc.getCollectionName()).getIndexInfo(), hasIndexNamed("active_1_lastMod_-1")); }
@Test public void testEmbeddedIndex() { final MappedClass mc = getMorphia().getMapper().addMappedClass(ContainsIndexedEmbed.class); assertThat(getDb().getCollection(mc.getCollectionName()).getIndexInfo(), doesNotHaveIndexNamed("e.name_-1")); getDs().ensureIndexes(ContainsIndexedEmbed.class); assertThat(getDb().getCollection(mc.getCollectionName()).getIndexInfo(), hasIndexNamed("e.name_-1")); }
@Test public void testInheritedFieldIndex() throws Exception { getMorphia().map(Circle.class) .map(Shape.class); getMorphia().getMapper() .getMappedClass(Circle.class); getDs().ensureIndexes(); final DBCollection coll = getDs().getCollection(Circle.class); assertEquals(4, coll.getIndexInfo() .size()); }
@Test public void testCanCreate2dSphereIndexesOnLegacyCoordinatePairs() { // given getMorphia().map(LegacyPlace.class); // when getDs().ensureIndexes(); // then List<DBObject> indexInfo = getDs().getCollection(LegacyPlace.class).getIndexInfo(); assertThat(indexInfo, hasIndexNamed("location_2dsphere")); }
@Test @SuppressWarnings("deprecation") public void testMultipleIndexedFields() { final MappedClass mc = getMorphia().getMapper().getMappedClass(Ad.class); getMorphia().map(Ad.class); assertThat(getDb().getCollection(mc.getCollectionName()).getIndexInfo(), doesNotHaveIndexNamed("lastMod_1_active_-1")); getDs().ensureIndex(Ad.class, "lastMod, -active"); assertThat(getDb().getCollection(mc.getCollectionName()).getIndexInfo(), hasIndexNamed("lastMod_1_active_-1")); }
@Test public void shouldCreateA2dIndexOnAnEntityWithArrayOfCoordinates() { // given PlaceWithLegacyCoords pointA = new PlaceWithLegacyCoords(new double[]{3.1, 5.2}, "Point A"); getDs().save(pointA); // when getDs().ensureIndexes(); // then List<DBObject> indexes = getDs().getCollection(PlaceWithLegacyCoords.class).getIndexInfo(); assertThat(indexes, hasIndexNamed("location_2d")); }
@Test public void testIndexedRecursiveEntity() throws Exception { final MappedClass mc = getMorphia().getMapper().getMappedClass(CircularEmbeddedEntity.class); getDs().ensureIndexes(); assertThat(getDb().getCollection(mc.getCollectionName()).getIndexInfo(), hasIndexNamed("a_1")); }
@Test(expected = DuplicateKeyException.class) public void testUniqueIndexedEntity() throws Exception { getDs().ensureIndexes(); assertThat(getDs().getCollection(UniqueIndexOnValue.class).getIndexInfo(), hasIndexNamed("l_ascending")); getDs().save(new UniqueIndexOnValue("a")); // this should throw... getDs().save(new UniqueIndexOnValue("v")); } @Test(expected = MappingException.class)