LEFT | RIGHT |
1 // Copyright 2011 Google Inc. All Rights Reserved. | 1 // Copyright 2011 Google Inc. All Rights Reserved. |
2 // | 2 // |
3 // Licensed under the Apache License, Version 2.0 (the "License"); | 3 // Licensed under the Apache License, Version 2.0 (the "License"); |
4 // you may not use this file except in compliance with the License. | 4 // you may not use this file except in compliance with the License. |
5 // You may obtain a copy of the License at | 5 // You may obtain a copy of the License at |
6 // | 6 // |
7 // http://www.apache.org/licenses/LICENSE-2.0 | 7 // http://www.apache.org/licenses/LICENSE-2.0 |
8 // | 8 // |
9 // Unless required by applicable law or agreed to in writing, software | 9 // Unless required by applicable law or agreed to in writing, software |
10 // distributed under the License is distributed on an "AS IS" BASIS, | 10 // distributed under the License is distributed on an "AS IS" BASIS, |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
43 private MockGsaFeedFileSender fileSender = new MockGsaFeedFileSender(); | 43 private MockGsaFeedFileSender fileSender = new MockGsaFeedFileSender(); |
44 private MockFeedArchiver fileArchiver = new MockFeedArchiver(); | 44 private MockFeedArchiver fileArchiver = new MockFeedArchiver(); |
45 private Journal journal = new Journal(new MockTimeProvider()); | 45 private Journal journal = new Journal(new MockTimeProvider()); |
46 private Config config = new Config(); | 46 private Config config = new Config(); |
47 private DocIdsMockAdaptor adaptor = new DocIdsMockAdaptor(); | 47 private DocIdsMockAdaptor adaptor = new DocIdsMockAdaptor(); |
48 private DocIdSender docIdSender = new DocIdSender(fileMaker, fileSender, | 48 private DocIdSender docIdSender = new DocIdSender(fileMaker, fileSender, |
49 fileArchiver, journal, config, adaptor); | 49 fileArchiver, journal, config, adaptor); |
50 private ExceptionHandler runtimeExceptionHandler | 50 private ExceptionHandler runtimeExceptionHandler |
51 = new RuntimeExceptionExceptionHandler(); | 51 = new RuntimeExceptionExceptionHandler(); |
52 | 52 |
53 private static final Map<GroupPrincipal, Collection<Principal>> SAMPLE_DATE | 53 private static final Map<GroupPrincipal, Collection<Principal>> SAMPLE_DATA |
54 = groupsSample(); | 54 = groupsSample(); |
55 private static final List<List<Map.Entry<GroupPrincipal, Collection<Principal>
>>> | 55 private static final |
56 NON_SPLITTED_EXPECTED_RESULT = nonsplittedExpectedResult(); | 56 List<List<Map.Entry<GroupPrincipal, Collection<Principal>>>> |
57 private static final List<List<Map.Entry<GroupPrincipal, Collection<Principal>
>>> | 57 NON_SPLITTED_EXPECTED_RESULT = nonSplittedExpectedResult(); |
58 SPLITTED_EXPECTED_RESULT = splittedPer2GroupsExpectedResult(); | 58 private static final |
| 59 List<List<Map.Entry<GroupPrincipal, Collection<Principal>>>> |
| 60 SPLITTED_EXPECTED_RESULT = splittedPer2GroupsExpectedResult(); |
59 | 61 |
60 @Rule | 62 @Rule |
61 public ExpectedException thrown = ExpectedException.none(); | 63 public ExpectedException thrown = ExpectedException.none(); |
62 | 64 |
63 @Before | 65 @Before |
64 public void setup() { | 66 public void setup() { |
65 config.setValue("gsa.hostname", "localhost"); | 67 config.setValue("gsa.hostname", "localhost"); |
66 config.setValue("gsa.version", "7.2.0-8"); | 68 config.setValue("gsa.version", "7.2.0-8"); |
67 } | 69 } |
68 | 70 |
(...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
348 thrown.expect(InternalErrorInTest.class); | 350 thrown.expect(InternalErrorInTest.class); |
349 try { | 351 try { |
350 docIdSender.pushIncrementalDocIdsFromAdaptor(listener, runtimeExceptionHan
dler); | 352 docIdSender.pushIncrementalDocIdsFromAdaptor(listener, runtimeExceptionHan
dler); |
351 } finally { | 353 } finally { |
352 assertEquals(CompletionStatus.FAILURE, journal.getLastIncrementalPushStatu
s()); | 354 assertEquals(CompletionStatus.FAILURE, journal.getLastIncrementalPushStatu
s()); |
353 } | 355 } |
354 } | 356 } |
355 | 357 |
356 @Test | 358 @Test |
357 public void testPushGroupsNormal() throws Exception { | 359 public void testPushGroupsNormal() throws Exception { |
358 List<List<Map.Entry<GroupPrincipal, Collection<Principal>>>> goldenGroups | |
359 = SPLITTED_EXPECTED_RESULT; | |
360 | |
361 config.setValue("feed.maxUrls", "2"); | 360 config.setValue("feed.maxUrls", "2"); |
362 assertNull(docIdSender.pushGroupDefinitions(SAMPLE_DATE, false, null)); | 361 assertNull(docIdSender.pushGroupDefinitions(SAMPLE_DATA, false, null)); |
363 | 362 |
364 assertEquals(2, fileMaker.i); | 363 assertEquals(2, fileMaker.i); |
365 assertEquals(goldenGroups, fileMaker.groupses); | 364 assertEquals(SPLITTED_EXPECTED_RESULT, fileMaker.groupses); |
366 assertEquals(Arrays.asList(new String[] { | 365 assertEquals(Arrays.asList(new String[] { |
367 "0", "1", | 366 "0", "1", |
368 }), fileSender.xmlStrings); | 367 }), fileSender.xmlStrings); |
369 assertEquals(Arrays.asList(new String[] {"0", "1"}), fileArchiver.feeds); | 368 assertEquals(Arrays.asList(new String[] {"0", "1"}), fileArchiver.feeds); |
370 assertTrue(fileArchiver.failedFeeds.isEmpty()); | 369 assertTrue(fileArchiver.failedFeeds.isEmpty()); |
371 } | 370 } |
372 | 371 |
373 @Test | 372 @Test |
374 public void testPushGroupsAllDocsPublic() throws Exception { | 373 public void testPushGroupsAllDocsPublic() throws Exception { |
375 config.setValue("adaptor.markAllDocsAsPublic", "true"); | 374 config.setValue("adaptor.markAllDocsAsPublic", "true"); |
376 assertNull(docIdSender.pushGroupDefinitions(SAMPLE_DATE, false, null)); | 375 assertNull(docIdSender.pushGroupDefinitions(SAMPLE_DATA, false, null)); |
377 | 376 |
378 assertEquals(0, fileMaker.i); | 377 assertEquals(0, fileMaker.i); |
379 assertTrue(fileMaker.groupses.isEmpty()); | 378 assertTrue(fileMaker.groupses.isEmpty()); |
380 assertTrue(fileArchiver.failedFeeds.isEmpty()); | 379 assertTrue(fileArchiver.failedFeeds.isEmpty()); |
381 } | 380 } |
382 | 381 |
383 @Test | 382 @Test |
384 public void testPushGroupsReplaceAllGroupsBeforeVersion74() throws Exception { | 383 public void testPushGroupsReplaceAllGroupsBeforeVersion74() throws Exception { |
385 List<List<Map.Entry<GroupPrincipal, Collection<Principal>>>> goldenGroups | |
386 = SPLITTED_EXPECTED_RESULT; | |
387 | |
388 config.setValue("feed.maxUrls", "2"); | 384 config.setValue("feed.maxUrls", "2"); |
389 journal.recordFullPushStarted(); | 385 journal.recordFullPushStarted(); |
390 assertNull(docIdSender.pushGroupDefinitions(SAMPLE_DATE, false, null)); | 386 assertNull(docIdSender.pushGroupDefinitions(SAMPLE_DATA, false, null)); |
391 journal.recordFullPushSuccessful(); | 387 journal.recordFullPushSuccessful(); |
392 | 388 |
393 assertEquals(2, fileMaker.i); | 389 assertEquals(2, fileMaker.i); |
394 assertEquals(goldenGroups, fileMaker.groupses); | 390 assertEquals(SPLITTED_EXPECTED_RESULT, fileMaker.groupses); |
395 assertEquals(Arrays.asList(new String[] {"0", "1"}), fileSender.xmlStrings); | 391 assertEquals(Arrays.asList(new String[] {"0", "1"}), fileSender.xmlStrings); |
396 assertEquals(Arrays.asList(new String[] {"0", "1"}), fileArchiver.feeds); | 392 assertEquals(Arrays.asList(new String[] {"0", "1"}), fileArchiver.feeds); |
397 assertTrue(fileArchiver.failedFeeds.isEmpty()); | 393 assertTrue(fileArchiver.failedFeeds.isEmpty()); |
398 } | 394 } |
399 | 395 |
400 @Test | 396 @Test |
401 public void testPushGroupsReplaceAllGroupsAtVersion740() throws Exception { | 397 public void testPushGroupsReplaceAllGroupsAtVersion740() throws Exception { |
402 config.setValue("gsa.version", "7.4.0-1"); | 398 config.setValue("gsa.version", "7.4.0-1"); |
403 docIdSender = new DocIdSender(fileMaker, fileSender, fileArchiver, journal, | 399 docIdSender = new DocIdSender(fileMaker, fileSender, fileArchiver, journal, |
404 config, adaptor); | 400 config, adaptor); |
405 List<List<Map.Entry<GroupPrincipal, Collection<Principal>>>> goldenGroups | |
406 = NON_SPLITTED_EXPECTED_RESULT; | |
407 | |
408 config.setValue("feed.maxUrls", "2"); // but this will be ignored | 401 config.setValue("feed.maxUrls", "2"); // but this will be ignored |
409 | 402 |
410 journal.recordFullPushStarted(); | 403 journal.recordFullPushStarted(); |
411 assertNull(docIdSender.pushGroupDefinitions(SAMPLE_DATE, false, null)); | 404 assertNull(docIdSender.pushGroupDefinitions(SAMPLE_DATA, false, null)); |
412 journal.recordFullPushSuccessful(); | 405 journal.recordFullPushSuccessful(); |
413 | 406 |
414 assertEquals(1, fileMaker.i); // non-incremental --> just one "batch" | 407 assertEquals(1, fileMaker.i); // non-incremental --> just one "batch" |
415 assertEquals(goldenGroups, fileMaker.groupses); | 408 assertEquals(NON_SPLITTED_EXPECTED_RESULT, fileMaker.groupses); |
416 assertEquals(Collections.singletonList("0"), fileSender.xmlStrings); | 409 assertEquals(Collections.singletonList("0"), fileSender.xmlStrings); |
417 assertEquals(Collections.singletonList("0"), fileArchiver.feeds); | 410 assertEquals(Collections.singletonList("0"), fileArchiver.feeds); |
418 assertTrue(fileArchiver.failedFeeds.isEmpty()); | 411 assertTrue(fileArchiver.failedFeeds.isEmpty()); |
419 } | 412 } |
420 | 413 |
421 @Test | 414 @Test |
422 public void testNamedResources() throws Exception { | 415 public void testNamedResources() throws Exception { |
423 config.setValue("feed.name", "testing"); | 416 config.setValue("feed.name", "testing"); |
424 assertNull(docIdSender.pushNamedResources( | 417 assertNull(docIdSender.pushNamedResources( |
425 Collections.singletonMap(new DocId("test"), Acl.EMPTY), | 418 Collections.singletonMap(new DocId("test"), Acl.EMPTY), |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
503 groups.put(new GroupPrincipal("g1"), | 496 groups.put(new GroupPrincipal("g1"), |
504 Arrays.asList(new UserPrincipal("u1"), new GroupPrincipal("g2"))); | 497 Arrays.asList(new UserPrincipal("u1"), new GroupPrincipal("g2"))); |
505 groups.put(new GroupPrincipal("g2"), | 498 groups.put(new GroupPrincipal("g2"), |
506 Arrays.asList(new UserPrincipal("u2"), new GroupPrincipal("g3"))); | 499 Arrays.asList(new UserPrincipal("u2"), new GroupPrincipal("g3"))); |
507 groups.put(new GroupPrincipal("g3"), | 500 groups.put(new GroupPrincipal("g3"), |
508 Arrays.asList(new UserPrincipal("u3"), new GroupPrincipal("g4"))); | 501 Arrays.asList(new UserPrincipal("u3"), new GroupPrincipal("g4"))); |
509 return Collections.unmodifiableMap(groups); | 502 return Collections.unmodifiableMap(groups); |
510 } | 503 } |
511 | 504 |
512 private static List<List<Map.Entry<GroupPrincipal, Collection<Principal>>>> | 505 private static List<List<Map.Entry<GroupPrincipal, Collection<Principal>>>> |
513 nonsplittedExpectedResult() { | 506 nonSplittedExpectedResult() { |
514 List<List<Map.Entry<GroupPrincipal, Collection<Principal>>>> goldenGroups | 507 List<List<Map.Entry<GroupPrincipal, Collection<Principal>>>> goldenGroups |
515 = new ArrayList<List<Map.Entry<GroupPrincipal, | 508 = new ArrayList<List<Map.Entry<GroupPrincipal, |
516 Collection<Principal>>>>(); | 509 Collection<Principal>>>>(); |
517 List<Map.Entry<GroupPrincipal, Collection<Principal>>> tmp | 510 List<Map.Entry<GroupPrincipal, Collection<Principal>>> tmp |
518 = new ArrayList<Map.Entry<GroupPrincipal, Collection<Principal>>>(); | 511 = new ArrayList<Map.Entry<GroupPrincipal, Collection<Principal>>>(); |
519 tmp.add(new SimpleImmutableEntry<GroupPrincipal, Collection<Principal>>( | 512 tmp.add(new SimpleImmutableEntry<GroupPrincipal, Collection<Principal>>( |
520 new GroupPrincipal("g1"), SAMPLE_DATE.get(new GroupPrincipal("g1")))); | 513 new GroupPrincipal("g1"), SAMPLE_DATA.get(new GroupPrincipal("g1")))); |
521 tmp.add(new SimpleImmutableEntry<GroupPrincipal, Collection<Principal>>( | 514 tmp.add(new SimpleImmutableEntry<GroupPrincipal, Collection<Principal>>( |
522 new GroupPrincipal("g2"), SAMPLE_DATE.get(new GroupPrincipal("g2")))); | 515 new GroupPrincipal("g2"), SAMPLE_DATA.get(new GroupPrincipal("g2")))); |
523 tmp.add(new SimpleImmutableEntry<GroupPrincipal, Collection<Principal>>( | 516 tmp.add(new SimpleImmutableEntry<GroupPrincipal, Collection<Principal>>( |
524 new GroupPrincipal("g3"), SAMPLE_DATE.get(new GroupPrincipal("g3")))); | 517 new GroupPrincipal("g3"), SAMPLE_DATA.get(new GroupPrincipal("g3")))); |
525 goldenGroups.add(tmp); | 518 goldenGroups.add(tmp); |
526 return goldenGroups; | 519 return goldenGroups; |
527 } | 520 } |
528 | 521 |
529 private static List<List<Map.Entry<GroupPrincipal, Collection<Principal>>>> | 522 private static List<List<Map.Entry<GroupPrincipal, Collection<Principal>>>> |
530 splittedPer2GroupsExpectedResult() { | 523 splittedPer2GroupsExpectedResult() { |
531 List<List<Map.Entry<GroupPrincipal, Collection<Principal>>>> goldenGroups | 524 List<List<Map.Entry<GroupPrincipal, Collection<Principal>>>> goldenGroups |
532 = new ArrayList<List<Map.Entry<GroupPrincipal, | 525 = new ArrayList<List<Map.Entry<GroupPrincipal, |
533 Collection<Principal>>>>(); | 526 Collection<Principal>>>>(); |
534 List<Map.Entry<GroupPrincipal, Collection<Principal>>> tmp | 527 List<Map.Entry<GroupPrincipal, Collection<Principal>>> tmp |
535 = new ArrayList<Map.Entry<GroupPrincipal, Collection<Principal>>>(); | 528 = new ArrayList<Map.Entry<GroupPrincipal, Collection<Principal>>>(); |
536 tmp.add(new SimpleImmutableEntry<GroupPrincipal, Collection<Principal>>( | 529 tmp.add(new SimpleImmutableEntry<GroupPrincipal, Collection<Principal>>( |
537 new GroupPrincipal("g1"), SAMPLE_DATE.get(new GroupPrincipal("g1")))); | 530 new GroupPrincipal("g1"), SAMPLE_DATA.get(new GroupPrincipal("g1")))); |
538 tmp.add(new SimpleImmutableEntry<GroupPrincipal, Collection<Principal>>( | 531 tmp.add(new SimpleImmutableEntry<GroupPrincipal, Collection<Principal>>( |
539 new GroupPrincipal("g2"), SAMPLE_DATE.get(new GroupPrincipal("g2")))); | 532 new GroupPrincipal("g2"), SAMPLE_DATA.get(new GroupPrincipal("g2")))); |
540 goldenGroups.add(tmp); | 533 goldenGroups.add(tmp); |
541 goldenGroups.add(Collections. | 534 goldenGroups.add(Collections. |
542 <Map.Entry<GroupPrincipal, Collection<Principal>>>singletonList( | 535 <Map.Entry<GroupPrincipal, Collection<Principal>>>singletonList( |
543 new SimpleImmutableEntry<GroupPrincipal, Collection<Principal>>( | 536 new SimpleImmutableEntry<GroupPrincipal, Collection<Principal>>( |
544 new GroupPrincipal("g3"), SAMPLE_DATE.get(new GroupPrincipal("g3")))))
; | 537 new GroupPrincipal("g3"), SAMPLE_DATA.get(new GroupPrincipal("g3")))))
; |
545 return goldenGroups; | 538 return goldenGroups; |
546 } | 539 } |
547 | 540 |
548 private static class MockGsaFeedFileMaker extends GsaFeedFileMaker { | 541 private static class MockGsaFeedFileMaker extends GsaFeedFileMaker { |
549 List<String> names = new ArrayList<String>(); | 542 List<String> names = new ArrayList<String>(); |
550 List<List<? extends DocIdSender.Item>> recordses | 543 List<List<? extends DocIdSender.Item>> recordses |
551 = new ArrayList<List<? extends DocIdSender.Item>>(); | 544 = new ArrayList<List<? extends DocIdSender.Item>>(); |
552 // Don't use generics because of limitations in Java | 545 // Don't use generics because of limitations in Java |
553 List<Object> groupses = new ArrayList<Object>(); | 546 List<Object> groupses = new ArrayList<Object>(); |
554 List<String> metadatases = new ArrayList<String>(); | 547 List<String> metadatases = new ArrayList<String>(); |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
656 @Override | 649 @Override |
657 public void getDocIds(DocIdPusher pusher) throws InterruptedException, | 650 public void getDocIds(DocIdPusher pusher) throws InterruptedException, |
658 IOException { | 651 IOException { |
659 timesGetDocIdsCalled++; | 652 timesGetDocIdsCalled++; |
660 for (List<DocIdPusher.Record> infos : pushItems) { | 653 for (List<DocIdPusher.Record> infos : pushItems) { |
661 pusher.pushRecords(infos); | 654 pusher.pushRecords(infos); |
662 } | 655 } |
663 } | 656 } |
664 } | 657 } |
665 } | 658 } |
LEFT | RIGHT |