@CacheSpec @CheckNoStats @Test(dataProvider = "caches") public void values_removeIf(Map<Integer, Integer> map, CacheContext context) { Predicate<Integer> isEven = value -> (value % 2) == 0; boolean hasEven = map.values().stream().anyMatch(isEven); boolean removedIfEven = map.values().removeIf(isEven); assertThat(map.values().stream().anyMatch(isEven), is(false)); assertThat(removedIfEven, is(hasEven)); if (removedIfEven) { assertThat(map.size(), is(lessThan(context.original().size()))); } }
public void assertRecord( int index, Object... values ) { assertThat( index, lessThan( records.size() ) ); assertArrayEquals( records.get( index ).fields(), values ); }
@Test public void propertyDescriptorComparator() throws IntrospectionException { ExtendedBeanInfo.PropertyDescriptorComparator c = new ExtendedBeanInfo.PropertyDescriptorComparator(); assertThat(c.compare(new PropertyDescriptor("a", null, null), new PropertyDescriptor("a", null, null)), equalTo(0)); assertThat(c.compare(new PropertyDescriptor("abc", null, null), new PropertyDescriptor("abc", null, null)), equalTo(0)); assertThat(c.compare(new PropertyDescriptor("a", null, null), new PropertyDescriptor("b", null, null)), lessThan(0)); assertThat(c.compare(new PropertyDescriptor("b", null, null), new PropertyDescriptor("a", null, null)), greaterThan(0)); assertThat(c.compare(new PropertyDescriptor("abc", null, null), new PropertyDescriptor("abd", null, null)), lessThan(0)); assertThat(c.compare(new PropertyDescriptor("xyz", null, null), new PropertyDescriptor("123", null, null)), greaterThan(0)); assertThat(c.compare(new PropertyDescriptor("a", null, null), new PropertyDescriptor("abc", null, null)), lessThan(0)); assertThat(c.compare(new PropertyDescriptor("abc", null, null), new PropertyDescriptor("a", null, null)), greaterThan(0)); assertThat(c.compare(new PropertyDescriptor("abc", null, null), new PropertyDescriptor("b", null, null)), lessThan(0)); assertThat(c.compare(new PropertyDescriptor(" ", null, null), new PropertyDescriptor("a", null, null)), lessThan(0)); assertThat(c.compare(new PropertyDescriptor("1", null, null), new PropertyDescriptor("a", null, null)), lessThan(0)); assertThat(c.compare(new PropertyDescriptor("a", null, null), new PropertyDescriptor("A", null, null)), greaterThan(0)); }
@Test void shouldGiveRangesWithinMaxValuesWhenMatchingWholeEnvelopeAtMaxLevel() { Envelope envelope = new Envelope( -8, 8, -8, 8 ); HilbertSpaceFillingCurve2D curve = new HilbertSpaceFillingCurve2D( envelope ); List<SpaceFillingCurve.LongRange> ranges = curve.getTilesIntersectingEnvelope( envelope ); assertThat( ranges.size(), equalTo( 1 ) ); assertThat( ranges.get( 0 ).max, lessThan( Long.MAX_VALUE ) ); assertThat( ranges.get( 0 ).min, greaterThan( Long.MIN_VALUE ) ); }
@Test @Ignore("Intended for use during development only") public void shouldBeFasterThanSynchronizedMap() throws InterruptedException { Map<Integer, WeakReference<String>> synchronizedMap = Collections.synchronizedMap(new WeakHashMap<Integer, WeakReference<String>>()); StopWatch mapTime = timeMultiThreaded("SynchronizedMap", synchronizedMap, v -> new WeakReference<>(String.valueOf(v))); System.out.println(mapTime.prettyPrint()); this.map.setDisableTestHooks(true); StopWatch cacheTime = timeMultiThreaded("WeakConcurrentCache", this.map, String::valueOf); System.out.println(cacheTime.prettyPrint()); // We should be at least 4 time faster assertThat(cacheTime.getTotalTimeSeconds(), is(lessThan(mapTime.getTotalTimeSeconds() / 4.0))); }
@Test(dataProvider = "schedule") public void schedule(long nanos, int expired) { when(cache.evictEntry(captor.capture(), any(), anyLong())).thenReturn(true); for (int timeout : new int[] { 25, 90, 240 }) { timerWheel.schedule(new Timer(TimeUnit.SECONDS.toNanos(timeout))); } timerWheel.advance(nanos); verify(cache, times(expired)).evictEntry(any(), any(), anyLong()); for (Node<?, ?> node : captor.getAllValues()) { assertThat(node.getVariableTime(), is(lessThan(nanos))); } }
@Test public void testGetValuePerformance() throws Exception { Assume.group(TestGroup.PERFORMANCE); Map<String, String> map = new HashMap<>(); map.put("key", "value"); EvaluationContext context = new StandardEvaluationContext(map); ExpressionParser spelExpressionParser = new SpelExpressionParser(); Expression expr = spelExpressionParser.parseExpression("#root['key']"); StopWatch s = new StopWatch(); s.start(); for (int i = 0; i < 10000; i++) { expr.getValue(context); } s.stop(); assertThat(s.getTotalTimeMillis(), lessThan(200L)); }
private void checkBounded( Supplier<NumberValue> supplier ) { for ( int i = 0; i < ITERATIONS; i++ ) { NumberValue value = supplier.get(); assertThat( value, notNullValue() ); assertThat( value.compareTo( ZERO_INT ), greaterThanOrEqualTo( 0 ) ); assertThat( value.compareTo( UPPER ), lessThan( 0 ) ); } } }
@Test void lastPageIdOfEmptyFileIsLessThanZero() throws IOException { configureStandardPageCache(); try ( PagedFile pagedFile = map( file( "a" ), filePageSize ) ) { assertThat( pagedFile.getLastPageId(), lessThan( 0L ) ); } }
@Test public void shouldCompareBasedOnName() { ResourceConfig resourceConfigA = new ResourceConfig("aaa"); ResourceConfig resourceConfigB = new ResourceConfig("bbb"); assertThat(resourceConfigA.compareTo(resourceConfigB), is(org.hamcrest.Matchers.lessThan(0))); assertThat(resourceConfigB.compareTo(resourceConfigA), is(greaterThan(0))); assertThat(resourceConfigA.compareTo(resourceConfigA), is(0)); } }
@Test public void shouldCompareDiskSpace() { assertThat(new DiskSpace(10L).compareTo(new DiskSpace(12L)), is(org.hamcrest.Matchers.lessThan(0))); assertThat(DiskSpace.unknownDiskSpace().compareTo(new DiskSpace(12L)), is(org.hamcrest.Matchers.lessThan(0))); assertThat(new DiskSpace(10L).compareTo(DiskSpace.unknownDiskSpace()), is(greaterThan(0))); assertThat(DiskSpace.unknownDiskSpace().compareTo(DiskSpace.unknownDiskSpace()), is(0)); }
@Test public void shouldCompare() { CaseInsensitiveString foo = new CaseInsensitiveString("foo"); CaseInsensitiveString fOO = new CaseInsensitiveString("fOO"); CaseInsensitiveString bar = new CaseInsensitiveString("bar"); assertThat(foo.compareTo(fOO), is(0)); assertThat(fOO.compareTo(foo), is(0)); assertThat(bar.compareTo(foo), lessThan(0)); assertThat(bar.compareTo(fOO), lessThan(0)); assertThat(foo.compareTo(bar), greaterThan(0)); assertThat(fOO.compareTo(bar), greaterThan(0)); }
@Test public void ipAddressComparator(){ assertThat(IpAddress.create("10.12.34.20").compareTo(IpAddress.create("10.12.34.3")),is(greaterThan(0))); assertThat(IpAddress.create("10.12.34.20").compareTo(IpAddress.create("10.12.34.20")),is(0)); assertThat(IpAddress.create("112.12.34.20").compareTo(IpAddress.create("10.12.34.20")), is(greaterThan(0))); assertThat(IpAddress.create("10.12.34.20").compareTo(IpAddress.create("")), is(greaterThan(0))); assertThat(IpAddress.create("").compareTo(IpAddress.create("10.12.34.3")), is(org.hamcrest.Matchers.lessThan(0))); assertThat(IpAddress.create("").compareTo(IpAddress.create("")), is(org.hamcrest.Matchers.lessThan(0))); assertThat(IpAddress.create("8:8:8:8:8:8:8:8").compareTo(IpAddress.create("10.12.34.20")), is(greaterThan(0))); }
@Test public void shouldCompareSortedCollections() { AlphaAsciiCollectionComparator<Foo> comparator = new AlphaAsciiCollectionComparator<>(); assertThat(comparator.compare(Arrays.asList(new Foo("foo"), new Foo("quux")), Arrays.asList(new Foo("foo"), new Foo("bar"))), greaterThan(0)); assertThat(comparator.compare(Arrays.asList(new Foo("foo"), new Foo("abc")), Arrays.asList(new Foo("foo"), new Foo("bar"))), lessThan(0)); assertThat(comparator.compare(Arrays.asList(new Foo("foo"), new Foo("bar")), Arrays.asList(new Foo("bar"), new Foo("foo"))), is(0)); } }
@Test public void testHonorsPassedInParams() throws Exception { BatchInserter inserter = BatchInserters.inserter( testDirectory.databaseDir(), fileSystemRule.get(), stringMap( GraphDatabaseSettings.pagecache_memory.name(), "280K" ) ); NeoStores neoStores = ReflectionUtil.getPrivateField( inserter, "neoStores", NeoStores.class ); PageCache pageCache = ReflectionUtil.getPrivateField( neoStores, "pageCache", PageCache.class ); inserter.shutdown(); long mappedMemoryTotalSize = MuninnPageCache.memoryRequiredForPages( pageCache.maxCachedPages() ); assertThat( "memory mapped config is active", mappedMemoryTotalSize, is( allOf( greaterThan( kibiBytes( 270 ) ), lessThan( kibiBytes( 290 ) ) ) ) ); }
@Test public void shouldUnderstandLesserLengthResourcesAsLesser() { ResourceConfigs resourceConfigsA = new ResourceConfigs(); ResourceConfigs resourceConfigsB = new ResourceConfigs(); resourceConfigsA.add(new ResourceConfig("xyz")); resourceConfigsB.add(new ResourceConfig("xyz")); resourceConfigsB.add(new ResourceConfig("zzz")); assertThat(resourceConfigsA.compareTo(resourceConfigsB), is(org.hamcrest.Matchers.lessThan(0))); assertThat(resourceConfigsB.compareTo(resourceConfigsA), is(greaterThan(0))); }
@Test public void shouldCompareBasedOnResourceListItHas() { ResourceConfigs resourceConfigsA = new ResourceConfigs(); ResourceConfigs resourceConfigsB = new ResourceConfigs(); resourceConfigsA.add(new ResourceConfig("xyz")); resourceConfigsA.add(new ResourceConfig("aaa")); resourceConfigsB.add(new ResourceConfig("xyz")); resourceConfigsB.add(new ResourceConfig("bbb")); assertThat(resourceConfigsA.compareTo(resourceConfigsB), is(org.hamcrest.Matchers.lessThan(0))); assertThat(resourceConfigsB.compareTo(resourceConfigsA), is(greaterThan(0))); }
@Test public void registerServletParamPropertySources_GenericWebApplicationContext() { MockServletContext servletContext = new MockServletContext(); servletContext.addInitParameter("pCommon", "pCommonContextValue"); servletContext.addInitParameter("pContext1", "pContext1Value"); GenericWebApplicationContext ctx = new GenericWebApplicationContext(); ctx.setServletContext(servletContext); ctx.refresh(); ConfigurableEnvironment environment = ctx.getEnvironment(); assertThat(environment, instanceOf(StandardServletEnvironment.class)); MutablePropertySources propertySources = environment.getPropertySources(); assertThat(propertySources.contains(StandardServletEnvironment.SERVLET_CONTEXT_PROPERTY_SOURCE_NAME), is(true)); // ServletContext params are available assertThat(environment.getProperty("pCommon"), is("pCommonContextValue")); assertThat(environment.getProperty("pContext1"), is("pContext1Value")); // Servlet* PropertySources have precedence over System* PropertySources assertThat(propertySources.precedenceOf(PropertySource.named(StandardServletEnvironment.SERVLET_CONTEXT_PROPERTY_SOURCE_NAME)), lessThan(propertySources.precedenceOf(PropertySource.named(StandardEnvironment.SYSTEM_PROPERTIES_PROPERTY_SOURCE_NAME)))); // Replace system properties with a mock property source for convenience MockPropertySource mockSystemProperties = new MockPropertySource(StandardEnvironment.SYSTEM_PROPERTIES_PROPERTY_SOURCE_NAME); mockSystemProperties.setProperty("pCommon", "pCommonSysPropsValue"); mockSystemProperties.setProperty("pSysProps1", "pSysProps1Value"); propertySources.replace(StandardEnvironment.SYSTEM_PROPERTIES_PROPERTY_SOURCE_NAME, mockSystemProperties); // assert that servletcontext init params resolve with higher precedence than sysprops assertThat(environment.getProperty("pCommon"), is("pCommonContextValue")); assertThat(environment.getProperty("pSysProps1"), is("pSysProps1Value")); }
@Test public void shouldOrderByHostname() throws Exception { AgentInstance agentA = new AgentInstance(new AgentConfig("UUID", "A", "127.0.0.1"), LOCAL, systemEnvironment, null); AgentInstance agentB = new AgentInstance(new AgentConfig("UUID", "B", "127.0.0.2"), LOCAL, systemEnvironment, null); assertThat(agentA.compareTo(agentA), is(0)); assertThat(agentA.compareTo(agentB), lessThan(0)); assertThat(agentB.compareTo(agentA), greaterThan(0)); }
@Test public void mustRecommendPageCacheMemory() { assertThat( recommendPageCacheMemory( mebiBytes( 100 ) ), between( mebiBytes( 95 ), mebiBytes( 105 ) ) ); assertThat( recommendPageCacheMemory( gibiBytes( 1 ) ), between( mebiBytes( 95 ), mebiBytes( 105 ) ) ); assertThat( recommendPageCacheMemory( gibiBytes( 3 ) ), between( mebiBytes( 470 ), mebiBytes( 530 ) ) ); assertThat( recommendPageCacheMemory( gibiBytes( 6 ) ), between( mebiBytes( 980 ), mebiBytes( 1048 ) ) ); assertThat( recommendPageCacheMemory( gibiBytes( 192 ) ), between( gibiBytes( 140 ), gibiBytes( 150 ) ) ); assertThat( recommendPageCacheMemory( gibiBytes( 1920 ) ), between( gibiBytes( 1850 ), gibiBytes( 1900 ) ) ); // Also never recommend more than 16 TiB of page cache memory, regardless of how much is available. assertThat( recommendPageCacheMemory( exbiBytes( 1 ) ), lessThan( tebiBytes( 17 ) ) ); }