function stepDynamicViewPersistence() {
  var query = {
    'age': {
      '$gt': 24
    }
  };

  // set up a persistent dynamic view with sort
  var pview = users.addDynamicView('test2', true);
  pview.applyFind(query);
  pview.applySimpleSort("age");

  // the dynamic view depends on an internal resultset
  // the persistent dynamic view also depends on an internal resultdata data array
  // filteredrows should be applied immediately to resultset will be lazily built into resultdata later when data() is called
  suite.assertStrictEqual("dynamic view initialization 1", pview.resultset.filteredrows.length, 3);
  suite.assertStrictEqual("dynamic view initialization 2", pview.resultdata.length, 0);

  // compare how many documents are in results before adding new ones
  var pviewResultsetLenBefore = pview.resultset.filteredrows.length;

  users.insert({
    name: 'abc',
    age: 21,
    lang: 'English'
  });

  users.insert({
    name: 'def',
    age: 25,
    lang: 'English'
  });

  // now see how many are in resultset (without rebuilding persistent view)
  var pviewResultsetLenAfter = pview.resultset.filteredrows.length;

  // only one document should have been added to resultset (1 was filtered out)
  suite.assertStrictEqual("dv resultset is 'set' valid", pviewResultsetLenBefore + 1, pviewResultsetLenAfter);

  // Test sorting and lazy build of resultdata

  // retain copy of internal resultset's filteredrows before lazy sort
  var frcopy = pview.resultset.filteredrows.slice();
  pview.data();
  // now make a copy of internal result's filteredrows after lazy sort
  var frcopy2 = pview.resultset.filteredrows.slice();

  // verify filteredrows logically matches resultdata (irrelevant of sort)
  for (var idxFR = 0; idxFR < frcopy2.length; idxFR++) {
    suite.assertEqual("dynamic view resultset/resultdata consistency", pview.resultdata[idxFR], pview.collection.data[frcopy2[idxFR]]);
  }
  // now verify they are not exactly equal (verify sort moved stuff)
  suite.assertNotEqual('dynamic view sort', frcopy, frcopy2);
}
// make sure view persistence works as expected
make sure view persistence works as expected
make sure view persistence works as expected
function stepDynamicViewPersistence() {
  var query = {
    'age': {
      '$gt': 24
    }
  };
  var pview = users.addDynamicView('test2', true);
  pview.applyFind(query);
  pview.applySimpleSort("age");
  suite.assertStrictEqual("dynamic view initialization 1", pview.resultset.filteredrows.length, 3);
  suite.assertStrictEqual("dynamic view initialization 2", pview.resultdata.length, 0);
  var pviewResultsetLenBefore = pview.resultset.filteredrows.length;
  users.insert({
    name: 'abc',
    age: 21,
    lang: 'English'
  });
  users.insert({
    name: 'def',
    age: 25,
    lang: 'English'
  });
  var pviewResultsetLenAfter = pview.resultset.filteredrows.length;
  suite.assertStrictEqual("dv resultset is 'set' valid", pviewResultsetLenBefore + 1, pviewResultsetLenAfter);
  var frcopy = pview.resultset.filteredrows.slice();
  pview.data();
  var frcopy2 = pview.resultset.filteredrows.slice();
  for (var idxFR = 0; idxFR < frcopy2.length; idxFR++) {
    suite.assertEqual("dynamic view resultset/resultdata consistency", pview.resultdata[idxFR], pview.collection.data[frcopy2[idxFR]]);
  }
  suite.assertNotEqual('dynamic view sort', frcopy, frcopy2);
}
function stepDynamicViewPersistence ( ) { var query = { 'age' : { '$gt' : 24 } } ; var pview = users . addDynamicView ( 'test2' , true ) ; pview . applyFind ( query ) ; pview . applySimpleSort ( "age" ) ; suite . assertStrictEqual ( "dynamic view initialization 1" , pview . resultset . filteredrows . length , 3 ) ; suite . assertStrictEqual ( "dynamic view initialization 2" , pview . resultdata . length , 0 ) ; var pviewResultsetLenBefore = pview . resultset . filteredrows . length ; users . insert ( { name : 'abc' , age : 21 , lang : 'English' } ) ; users . insert ( { name : 'def' , age : 25 , lang : 'English' } ) ; var pviewResultsetLenAfter = pview . resultset . filteredrows . length ; suite . assertStrictEqual ( "dv resultset is 'set' valid" , pviewResultsetLenBefore + 1 , pviewResultsetLenAfter ) ; var frcopy = pview . resultset . filteredrows . slice ( ) ; pview . data ( ) ; var frcopy2 = pview . resultset . filteredrows . slice ( ) ; for ( var idxFR = 0 ; idxFR < frcopy2 . length ; idxFR ++ ) { suite . assertEqual ( "dynamic view resultset/resultdata consistency" , pview . resultdata [ idxFR ] , pview . collection . data [ frcopy2 [ idxFR ] ] ) ; } suite . assertNotEqual ( 'dynamic view sort' , frcopy , frcopy2 ) ; }
make sure view persistence works as expected
make sure view persistence works as expected
// set up a persistent dynamic view with sort // the dynamic view depends on an internal resultset // the persistent dynamic view also depends on an internal resultdata data array // filteredrows should be applied immediately to resultset will be lazily built into resultdata later when data() is called // compare how many documents are in results before adding new ones // now see how many are in resultset (without rebuilding persistent view) // only one document should have been added to resultset (1 was filtered out) // Test sorting and lazy build of resultdata // retain copy of internal resultset's filteredrows before lazy sort // now make a copy of internal result's filteredrows after lazy sort // verify filteredrows logically matches resultdata (irrelevant of sort) // now verify they are not exactly equal (verify sort moved stuff)