コード例 #1
0
 @Test
 public void testBug37723() {
   Region region = CacheUtils.createRegion("portfolios", Portfolio.class);
   region.put("0", new Portfolio(0));
   region.put("1", new Portfolio(1));
   region.put("2", new Portfolio(2));
   region.put("3", new Portfolio(3));
   QueryService qs = CacheUtils.getQueryService();
   String qry =
       "select distinct getID, status from /portfolios pf where getID < 10 order by getID desc";
   Query q = qs.newQuery(qry);
   try {
     SelectResults result = (SelectResults) q.execute();
     Iterator itr = result.iterator();
     int j = 3;
     while (itr.hasNext()) {
       Struct struct = (Struct) itr.next();
       assertEquals(j--, ((Integer) struct.get("getID")).intValue());
     }
     qry = "select distinct getID, status from /portfolios pf where getID < 10 order by getID asc";
     q = qs.newQuery(qry);
     result = (SelectResults) q.execute();
     itr = result.iterator();
     j = 0;
     while (itr.hasNext()) {
       Struct struct = (Struct) itr.next();
       assertEquals(j++, ((Integer) struct.get("getID")).intValue());
     }
   } catch (Exception e) {
     e.printStackTrace();
     fail("Test failed because of exception=" + e);
   }
 }
コード例 #2
0
  @Test
  public void testBug40428_2() throws Exception {
    Object shortData1 =
        new Object() {
          public short shortField = 4;
        };
    Object shortData2 =
        new Object() {
          public short shortField = 5;
        };

    Region region = CacheUtils.createRegion("shortFieldTest", Object.class);
    region.put("0", shortData1);
    QueryService qs = CacheUtils.getQueryService();
    String qry = "select * from /shortFieldTest.entries sf where sf.value.shortField < 10 ";
    qs.createIndex(
        "shortIndex", IndexType.FUNCTIONAL, "value.shortField", "/shortFieldTest.entries");
    region.put("1", shortData2);
    Query query = null;
    Object result = null;

    query = qs.newQuery(qry);

    SelectResults rs = (SelectResults) query.execute();
    assertEquals(rs.size(), 2);
  }
コード例 #3
0
 public void xtestNestQueryInWhereClause() throws Exception {
   Region region = CacheUtils.createRegion("Portfolios", Portfolio.class);
   region.put("0", new Portfolio(0));
   region.put("1", new Portfolio(1));
   region.put("2", new Portfolio(2));
   region.put("3", new Portfolio(3));
   Query query =
       CacheUtils.getQueryService()
           .newQuery(
               "SELECT DISTINCT * FROM /Portfolios WHERE NOT (SELECT DISTINCT * FROM positions.values p WHERE p.secId = 'IBM').isEmpty");
   Collection result = (Collection) query.execute();
   Portfolio p = (Portfolio) (result.iterator().next());
   if (!p.positions.containsKey("IBM")) fail(query.getQueryString());
   // query = CacheUtils.getQueryService().newQuery("SELECT DISTINCT * FROM
   // /Portfolios where status = ELEMENT(SELECT DISTINCT * FROM /Portfolios p
   // where p.ID = 0).status");
   // result = (Collection)query.execute();
   // CacheUtils.log(result);
   // query = CacheUtils.getQueryService().newQuery("SELECT DISTINCT * FROM
   // /Portfolios x where status = ELEMENT(SELECT DISTINCT * FROM /Portfolios
   // p where p.ID = x.ID).status");
   // result = (Collection)query.execute();
   // SELECT DISTINCT * FROM /Portfolios where status = ELEMENT(SELECT
   // DISTINCT * FROM /Portfolios where ID = 0).status
   // SELECT DISTINCT * FROM /Portfolios x where status = ELEMENT(SELECT
   // DISTINCT * FROM /Portfolios p where p.ID = x.ID).status
 }
コード例 #4
0
 @Before
 public void setUp() throws java.lang.Exception {
   CacheUtils.startCache();
   Region region = CacheUtils.createRegion("portfolios", Portfolio.class);
   for (int i = 0; i < 4; i++) {
     region.put("" + i, new Portfolio(i));
     // CacheUtils.log(new Portfolio(i));
   }
 }
コード例 #5
0
  @Test
  public void testBug37119() throws Exception {
    Region region = CacheUtils.createRegion("portfolios", Portfolio.class);
    region.put("0", new Portfolio(0));
    region.put("1", new Portfolio(1));
    region.put("2", new Portfolio(2));
    region.put("3", new Portfolio(3));
    region.put(Integer.MIN_VALUE + "", new Portfolio(Integer.MIN_VALUE));
    region.put("-1", new Portfolio(-1));
    QueryService qs = CacheUtils.getQueryService();

    String qStr = "Select distinct * from /portfolios pf where pf.getID() = " + Integer.MIN_VALUE;
    Query q = qs.newQuery(qStr);
    SelectResults result = (SelectResults) q.execute();
    assertEquals(result.size(), 1);
    Portfolio pf = (Portfolio) result.iterator().next();
    assertEquals(pf.getID(), Integer.MIN_VALUE);
    qStr = "Select distinct * from /portfolios pf where pf.getID() = -1";
    q = qs.newQuery(qStr);
    result = (SelectResults) q.execute();
    assertEquals(result.size(), 1);
    pf = (Portfolio) result.iterator().next();
    assertEquals(pf.getID(), -1);

    qStr =
        "Select distinct * from /portfolios pf where pf.getID() = 3 and pf.getLongMinValue() = "
            + Long.MIN_VALUE
            + 'l';
    q = qs.newQuery(qStr);
    result = (SelectResults) q.execute();
    assertEquals(result.size(), 1);
    pf = (Portfolio) result.iterator().next();
    assertEquals(pf.getID(), 3);

    qStr =
        "Select distinct * from /portfolios pf where pf.getID() = 3 and pf.getFloatMinValue() = "
            + Float.MIN_VALUE
            + 'f';
    q = qs.newQuery(qStr);
    result = (SelectResults) q.execute();
    assertEquals(result.size(), 1);
    pf = (Portfolio) result.iterator().next();
    assertEquals(pf.getID(), 3);

    qStr =
        "Select distinct * from /portfolios pf where pf.getID() = 3 and pf.getDoubleMinValue() = "
            + Double.MIN_VALUE;
    q = qs.newQuery(qStr);
    result = (SelectResults) q.execute();
    assertEquals(result.size(), 1);
    pf = (Portfolio) result.iterator().next();
    assertEquals(pf.getID(), 3);
  }
コード例 #6
0
 public void xtestVoidMethods() throws Exception {
   Region region = CacheUtils.createRegion("Data", Data.class);
   region.put("0", new Data());
   Query query =
       CacheUtils.getQueryService().newQuery("SELECT DISTINCT * FROM /Data where voidMethod");
   Collection result = (Collection) query.execute();
   if (result.size() != 0) fail(query.getQueryString());
   query =
       CacheUtils.getQueryService()
           .newQuery("SELECT DISTINCT * FROM /Data where voidMethod = null ");
   result = (Collection) query.execute();
   if (result.size() != 1) fail(query.getQueryString());
 }
コード例 #7
0
 /**
  * Tests the where clause formed with CompiledComparison nesting with CompiledIN
  *
  * @throws Exception
  */
 @Test
 public void testBug40333_InLocalRegion_2() throws Exception {
   CacheUtils.startCache();
   final Cache cache = CacheUtils.getCache();
   AttributesFactory attributesFactory = new AttributesFactory();
   RegionAttributes ra = attributesFactory.create();
   final Region region = cache.createRegion("new_pos", ra);
   String queryStr =
       " select distinct r.name, pVal, r.\"type\"  "
           + " from /new_pos r , r.positions.values pVal where "
           + " ( r.name IN Set('name_11' , 'name_12') OR false ) AND pVal.mktValue = 1.00";
   this.bug40333Simulation(region, queryStr);
 }
コード例 #8
0
 public void xtestNestQueryInFromClause() throws Exception {
   Region region = CacheUtils.createRegion("Portfolios", Portfolio.class);
   region.put("0", new Portfolio(0));
   region.put("1", new Portfolio(1));
   region.put("2", new Portfolio(2));
   region.put("3", new Portfolio(3));
   Query query =
       CacheUtils.getQueryService()
           .newQuery(
               "SELECT DISTINCT * FROM (SELECT DISTINCT * FROM /Portfolios where status = 'active') p  where p.ID = 0");
   //    DebuggerSupport.waitForJavaDebugger(CacheUtils.getLogger());
   Collection result = (Collection) query.execute();
   Portfolio p = (Portfolio) (result.iterator().next());
   if (!p.status.equals("active") || p.getID() != 0) fail(query.getQueryString());
 }
コード例 #9
0
  @Test
  public void testAllIndexesOnCommitForPut() throws Exception {
    // create region
    AttributesFactory af = new AttributesFactory();
    af.setDataPolicy(DataPolicy.REPLICATE);
    Region region = cache.createRegion("sample", af.create());

    // put data
    for (int i = 0; i < 10; i++) {
      region.put(i, new Portfolio(i));
    }

    String[] queries = {
      "select * from /sample where ID = 5",
      "select ID from /sample where ID < 5",
      "select ID from /sample where ID > 5",
      "select ID from /sample where ID != 5",
      "select status from /sample where status = 'active'",
      "select status from /sample where status > 'active'",
      "select status from /sample where status < 'active'",
      "select status from /sample where status != 'active'",
      "select pos.secId from /sample p, p.positions.values pos where pos.secId = 'IBM'",
      "select pos.secId from /sample p, p.positions.values pos where pos.secId < 'VMW'",
      "select pos.secId from /sample p, p.positions.values pos where pos.secId > 'IBM'",
      "select pos.secId from /sample p, p.positions.values pos where pos.secId != 'IBM'"
    };

    SelectResults[][] sr = new SelectResults[queries.length][2];

    // execute queries without indexes
    for (int i = 0; i < queries.length; i++) {
      sr[i][0] = (SelectResults) qs.newQuery(queries[i]).execute();
    }

    // create indexes
    qs.createKeyIndex("IDIndex", "ID", "/sample");
    qs.createIndex("statusIndex", "status", "/sample");
    qs.createIndex("secIdIndex", "pos.secId", "/sample p, p.positions.values pos");

    // begin transaction
    Context ctx = cache.getJNDIContext();
    UserTransaction utx = (UserTransaction) ctx.lookup("java:/UserTransaction");
    utx.begin();

    // update data
    for (int i = 0; i < 10; i++) {
      region.put(i, new Portfolio(i));
    }

    // execute queries with indexes during transaction
    for (int i = 0; i < queries.length; i++) {
      sr[i][1] = (SelectResults) qs.newQuery(queries[i]).execute();
    }

    // complete transaction
    utx.commit();

    // verify results
    com.gemstone.gemfire.cache.query.CacheUtils.compareResultsOfWithAndWithoutIndex(sr);
  }
コード例 #10
0
 /**
  * Commented the test as it is for some reason causing OOM when run in the suite. It is due to
  * presence of PR Tests the where clause formed with CompiledComparison nesting with CompiledIN
  *
  * @throws Exception
  */
 public void _testBug40333_InPartitionedRegion_2() throws Exception {
   CacheUtils.startCache();
   final Cache cache = CacheUtils.getCache();
   AttributesFactory attributesFactory = new AttributesFactory();
   PartitionAttributesFactory paf = new PartitionAttributesFactory();
   paf.setTotalNumBuckets(10);
   PartitionAttributes pa = paf.create();
   attributesFactory.setPartitionAttributes(pa);
   RegionAttributes ra = attributesFactory.create();
   final Region region = cache.createRegion("new_pos", ra);
   String queryStr =
       " select distinct r.name, pVal, r.\"type\"  "
           + " from /new_pos r , r.positions.values pVal where "
           + " ( r.name IN Set('name_11' , 'name_12') OR false ) AND pVal.mktValue < 1.00";
   this.bug40333Simulation(region, queryStr);
 }
コード例 #11
0
  @Test
  public void testFilterProfile() throws Exception {
    Cache cache = CacheUtils.getCache();
    try {
      createLocalRegion();
      LocalRegion region = (LocalRegion) cache.getRegion(regionName);
      final FilterProfile filterProfile = new FilterProfile(region);
      filterProfile.registerClientInterest(
          "clientId", ".*", InterestType.REGULAR_EXPRESSION, false);

      final FilterProfileTestHook hook = new FilterProfileTestHook();
      FilterProfile.testHook = hook;

      new Thread(
              new Runnable() {
                public void run() {
                  while (hook.getCount() != 1) {}

                  filterProfile.unregisterClientInterest(
                      "clientId", ".*", InterestType.REGULAR_EXPRESSION);
                }
              })
          .start();
      filterProfile.hasAllKeysInterestFor("clientId");
    } finally {
      cache.getDistributedSystem().disconnect();
      cache.close();
    }
  }
コード例 #12
0
 /** Helper Methods */
 private void createLocalRegion() throws ParseException {
   Cache cache = CacheUtils.getCache();
   AttributesFactory attributesFactory = new AttributesFactory();
   attributesFactory.setDataPolicy(DataPolicy.NORMAL);
   RegionAttributes regionAttributes = attributesFactory.create();
   Region region = cache.createRegion(regionName, regionAttributes);
 }
コード例 #13
0
  @Test
  public void testMultipleOrderByClauses() {
    Region region = CacheUtils.createRegion("portfolios", Portfolio.class);
    region.put("2", new Portfolio(2));
    region.put("3", new Portfolio(3));
    region.put("4", new Portfolio(4));
    region.put("5", new Portfolio(5));
    region.put("6", new Portfolio(6));
    region.put("7", new Portfolio(7));
    QueryService qs = CacheUtils.getQueryService();
    String qry =
        "select distinct status, getID from /portfolios pf where getID < 10 order by status asc, getID desc";
    Query q = qs.newQuery(qry);
    try {
      SelectResults result = (SelectResults) q.execute();
      Iterator itr = result.iterator();
      int j = 6;
      while (itr.hasNext() && j > 0) {
        Struct struct = (Struct) itr.next();
        assertEquals("active", struct.get("status"));
        assertEquals(j, ((Integer) struct.get("getID")).intValue());

        j -= 2;
      }
      j = 7;
      while (itr.hasNext()) {
        Struct struct = (Struct) itr.next();
        assertEquals(j, ((Integer) struct.get("getID")).intValue());
        assertEquals("inactive", struct.get("status"));
        j -= 2;
      }
      /*
      qry = "select distinct getID, status from /portfolios pf where getID < 10 order by getID asc";
      q = qs.newQuery(qry);
      result = (SelectResults) q.execute();
      itr = result.iterator();
      j = 0;
      while ( itr.hasNext()) {
       Struct struct = (Struct)itr.next();
       assertEquals(j++, ((Integer)struct.get("getID")).intValue());
      }*/
    } catch (Exception e) {
      e.printStackTrace();
      fail("Test failed because of exception=" + e);
    }
  }
コード例 #14
0
  @Test
  public void testBug()
      throws TimeoutException, CacheWriterException, FunctionDomainException, TypeMismatchException,
          NameResolutionException, QueryInvocationTargetException, Exception {
    Region region = CacheUtils.createRegion("portfolios", Portfolio.class);
    region.put("0", new Portfolio(0));
    region.put("1", new Portfolio(1));
    region.put("2", new Portfolio(2));
    region.put("3", new Portfolio(3));
    QueryService qs = CacheUtils.getQueryService();
    /*String qStr = "Select distinct structset.sos, structset.key " +
    "from /portfolios pfos, pfos.positions.values outerPos, " +
    "(SELECT DISTINCT key: key, sos: pos.sharesOutstanding "+
    "from /portfolios.entries pf, pf.value.positions.values pos " +
    "where outerPos.secId != 'IBM' AND " +
    "pf.key IN (select distinct * from pf.value.collectionHolderMap['0'].arr)) structset " +
     "where structset.sos > 2000";*/

    String qStr =
        "Select distinct * from /portfolios pf, pf.positions.values where status = 'active' and secId = 'IBM'";
    qs.createIndex("index1", IndexType.FUNCTIONAL, "status", "/portfolios pf");

    qs.createIndex(
        "index4",
        IndexType.FUNCTIONAL,
        "itr",
        "/portfolios pf, pf.collectionHolderMap chm, chm.value.arr itr");
    qs.createIndex(
        "index2", IndexType.FUNCTIONAL, "status", "/portfolios pf, positions.values pos");
    qs.createIndex("index3", IndexType.FUNCTIONAL, "secId", "/portfolios pf, positions.values pos");
    qs.createIndex(
        "index5",
        IndexType.FUNCTIONAL,
        "pos.secId",
        "/portfolios pf, pf.collectionHolderMap chm, chm.value.arr, pf.positions.values pos");
    qs.createIndex(
        "index6", IndexType.FUNCTIONAL, "status", "/portfolios pf, pf.collectionHolderMap chm");
    qs.createIndex(
        "index7",
        IndexType.FUNCTIONAL,
        "itr",
        "/portfolios pf, positions.values, pf.collectionHolderMap chm, chm.value.arr itr");
    Query q = qs.newQuery(qStr);
    SelectResults result = (SelectResults) q.execute();
    if (result.size() == 0) fail("Test failed as size is zero");
  }
コード例 #15
0
 public void xtestMiscQueries() throws Exception {
   String testData[] = {"NULL", "UNDEFINED"};
   for (int i = 0; i < testData.length; i++) {
     Query query = CacheUtils.getQueryService().newQuery("SELECT DISTINCT * FROM " + testData[i]);
     Object result = query.execute();
     if (!result.equals(QueryService.UNDEFINED)) fail(query.getQueryString());
   }
 }
コード例 #16
0
  @Test
  public void testBug40441() throws Exception {
    CacheUtils.startCache();
    final Cache cache = CacheUtils.getCache();
    AttributesFactory attributesFactory = new AttributesFactory();
    RegionAttributes ra = attributesFactory.create();
    final Region region = cache.createRegion("new_pos", ra);
    String queryStr1 =
        " select distinct r.name, pVal, r.\"type\"  "
            + " from /new_pos r , r.positions.values pVal where "
            + " ( r.undefinedTestField.toString = UNDEFINED  OR false ) "; // AND pVal.mktValue =
                                                                           // 1.00";
    String queryStr2 =
        " select distinct r.name, pVal, r.\"type\"  "
            + " from /new_pos r , r.positions.values pVal where "
            + " ( r.undefinedTestField.toString = UNDEFINED  AND true ) AND pVal.mktValue = 1.00";
    final QueryService qs = CacheUtils.getQueryService();
    for (int i = 1; i < 100; ++i) {
      NewPortfolio pf = new NewPortfolio("name" + i, i);
      region.put("name" + i, pf);
    }

    Index indx1 =
        qs.createIndex(
            "MarketValues",
            IndexType.FUNCTIONAL,
            "itr2.mktValue",
            "/new_pos itr1, itr1.positions.values itr2");
    Index indx2 = qs.createIndex("Name", IndexType.FUNCTIONAL, "itr1.name", "/new_pos itr1");
    Index indx3 = qs.createIndex("nameIndex", IndexType.PRIMARY_KEY, "name", "/new_pos");
    Index indx4 = qs.createIndex("idIndex", IndexType.FUNCTIONAL, "id", "/new_pos");
    Index indx5 = qs.createIndex("statusIndex", IndexType.FUNCTIONAL, "status", "/new_pos");
    Index indx6 =
        qs.createIndex(
            "undefinedFieldIndex", IndexType.FUNCTIONAL, "undefinedTestField.toString", "/new_pos");
    final Query q1 = qs.newQuery(queryStr1);
    final Query q2 = qs.newQuery(queryStr2);
    try {
      SelectResults sr1 = (SelectResults) q1.execute();
      SelectResults sr2 = (SelectResults) q2.execute();
    } catch (Throwable e) {
      e.printStackTrace();
      fail("Test failed due to = " + e.toString());
    }
  }
コード例 #17
0
 @Override
 public Region createRegion(String regionName, Class valueConstraint) {
   PartitionAttributesFactory paf = new PartitionAttributesFactory();
   AttributesFactory af = new AttributesFactory();
   af.setPartitionAttributes(paf.create());
   af.setValueConstraint(valueConstraint);
   Region r1 = CacheUtils.createRegion(regionName, af.create(), false);
   return r1;
 }
コード例 #18
0
  @Test
  public void testBestIndexPick() throws Exception {
    QueryService qs;

    qs = CacheUtils.getQueryService();
    qs.createIndex("statusIndex", IndexType.FUNCTIONAL, "status", "/portfolios, positions");
    QCompiler compiler = new QCompiler();
    List list = compiler.compileFromClause("/portfolios pf");
    ExecutionContext context = new QueryExecutionContext(null, CacheUtils.getCache());
    context.newScope(context.assosciateScopeID());

    Iterator iter = list.iterator();
    while (iter.hasNext()) {
      CompiledIteratorDef iterDef = (CompiledIteratorDef) iter.next();
      context.addDependencies(new CompiledID("dummy"), iterDef.computeDependencies(context));
      RuntimeIterator rIter = iterDef.getRuntimeIterator(context);
      context.bindIterator(rIter);
      context.addToIndependentRuntimeItrMap(iterDef);
    }
    CompiledPath cp = new CompiledPath(new CompiledID("pf"), "status");

    // TASK ICM1
    String[] defintions = {"/portfolios", "index_iter1.positions"};
    IndexData id =
        IndexUtils.findIndex(
            "/portfolios", defintions, cp, "*", CacheUtils.getCache(), true, context);
    Assert.assertEquals(id.getMatchLevel(), 0);
    Assert.assertEquals(id.getMapping()[0], 1);
    Assert.assertEquals(id.getMapping()[1], 2);
    String[] defintions1 = {"/portfolios"};
    IndexData id1 =
        IndexUtils.findIndex(
            "/portfolios", defintions1, cp, "*", CacheUtils.getCache(), true, context);
    Assert.assertEquals(id1.getMatchLevel(), -1);
    Assert.assertEquals(id1.getMapping()[0], 1);
    String[] defintions2 = {"/portfolios", "index_iter1.positions", "index_iter1.coll1"};
    IndexData id2 =
        IndexUtils.findIndex(
            "/portfolios", defintions2, cp, "*", CacheUtils.getCache(), true, context);
    Assert.assertEquals(id2.getMatchLevel(), 1);
    Assert.assertEquals(id2.getMapping()[0], 1);
    Assert.assertEquals(id2.getMapping()[1], 2);
    Assert.assertEquals(id2.getMapping()[2], 0);
  }
コード例 #19
0
 public void xtestBug32763()
     throws FunctionDomainException, TypeMismatchException, NameResolutionException,
         QueryInvocationTargetException, TimeoutException, CacheWriterException {
   Region region = CacheUtils.createRegion("pos", Portfolio.class);
   region.put("0", new Portfolio(0));
   region.put("1", new Portfolio(1));
   region.put("2", new Portfolio(2));
   region.put("3", new Portfolio(3));
   QueryService qs = CacheUtils.getQueryService();
   String qStr =
       "SELECT DISTINCT key: key, iD: entry.value.iD, secId: posnVal.secId  FROM /pos.entries entry, entry.value.positions.values posnVal  WHERE entry.value.\"type\" = 'type0' AND posnVal.secId = 'YHOO'";
   Query q = qs.newQuery(qStr);
   SelectResults result = (SelectResults) q.execute();
   StructType type = (StructType) result.getCollectionType().getElementType();
   String names[] = type.getFieldNames();
   List list = result.asList();
   if (list.size() < 1) fail("Test failed as the resultset's size is zero");
   for (int i = 0; i < list.size(); ++i) {
     Struct stc = (Struct) list.get(i);
     if (!stc.get(names[2]).equals("YHOO")) {
       fail("Test failed as the SecID value is not YHOO");
     }
   }
 }
コード例 #20
0
 @After
 public void tearDown() throws java.lang.Exception {
   CacheUtils.closeCache();
 }
コード例 #21
0
  private void bug40333Simulation(final Region region, final String queryStr) throws Exception {
    final QueryService qs = CacheUtils.getQueryService();
    Region rgn = CacheUtils.getRegion("/new_pos");
    for (int i = 1; i < 100; ++i) {
      NewPortfolio pf = new NewPortfolio("name" + i, i);
      rgn.put("name" + i, pf);
    }
    final Object lock = new Object();
    final boolean[] expectionOccured = new boolean[] {false};
    final boolean[] keepGoing = new boolean[] {true};

    Thread indexCreatorDestroyer =
        new Thread(
            new Runnable() {
              public void run() {
                boolean continueRunning = true;
                do {

                  synchronized (lock) {
                    continueRunning = keepGoing[0];
                  }
                  try {
                    Index indx1 =
                        qs.createIndex(
                            "MarketValues",
                            IndexType.FUNCTIONAL,
                            "itr2.mktValue",
                            "/new_pos itr1, itr1.positions.values itr2");
                    Index indx2 =
                        qs.createIndex("Name", IndexType.FUNCTIONAL, "itr1.name", "/new_pos itr1");
                    Index indx3 =
                        qs.createIndex("nameIndex", IndexType.PRIMARY_KEY, "name", "/new_pos");
                    Index indx4 = qs.createIndex("idIndex", IndexType.FUNCTIONAL, "id", "/new_pos");
                    Index indx5 =
                        qs.createIndex("statusIndex", IndexType.FUNCTIONAL, "status", "/new_pos");
                    Index indx6 =
                        qs.createIndex(
                            "undefinedFieldIndex",
                            IndexType.FUNCTIONAL,
                            "undefinedTestField.toString",
                            "/new_pos");
                    Thread.sleep(800);
                    qs.removeIndex(indx1);
                    qs.removeIndex(indx2);
                    qs.removeIndex(indx3);
                    qs.removeIndex(indx4);
                    qs.removeIndex(indx5);
                    qs.removeIndex(indx6);
                  } catch (Throwable e) {
                    region.getCache().getLogger().error(e);
                    e.printStackTrace();
                    synchronized (lock) {
                      expectionOccured[0] = true;
                      keepGoing[0] = false;
                      continueRunning = false;
                    }
                  }
                } while (continueRunning);
              }
            });

    indexCreatorDestroyer.start();
    final Query q = qs.newQuery(queryStr);
    final int THREAD_COUNT = 10;
    Thread queryThreads[] = new Thread[THREAD_COUNT];
    final int numTimesToRun = 75;
    for (int i = 0; i < THREAD_COUNT; ++i) {
      queryThreads[i] =
          new Thread(
              new Runnable() {
                public void run() {
                  boolean continueRunning = true;
                  for (int i = 0; i < numTimesToRun && continueRunning; ++i) {
                    synchronized (lock) {
                      continueRunning = keepGoing[0];
                    }
                    try {
                      SelectResults sr = (SelectResults) q.execute();
                    } catch (Throwable e) {
                      e.printStackTrace();
                      region.getCache().getLogger().error(e);
                      synchronized (lock) {
                        expectionOccured[0] = true;
                        keepGoing[0] = false;
                        continueRunning = false;
                      }
                      break;
                    }
                  }
                }
              });
    }
    synchronized (lock) {
      assertFalse(expectionOccured[0]);
    }

    for (int i = 0; i < THREAD_COUNT; ++i) {
      queryThreads[i].start();
    }

    for (int i = 0; i < THREAD_COUNT; ++i) {
      queryThreads[i].join();
    }
    synchronized (lock) {
      keepGoing[0] = false;
    }

    indexCreatorDestroyer.join();
    synchronized (lock) {
      assertFalse(expectionOccured[0]);
    }
  }
コード例 #22
0
 @Before
 public void setUp() throws java.lang.Exception {
   CacheUtils.startCache();
 }