src_fm_fc_ms_ff
stringlengths
43
86.8k
target
stringlengths
20
276k
ArezContext { @OmitSymbol( unless = "arez.enable_task_interceptor" ) public void setTaskInterceptor( @Nullable final TaskInterceptor taskInterceptor ) { if ( Arez.shouldCheckInvariants() ) { invariant( Arez::isTaskInterceptorEnabled, () -> "Arez-0039: setTaskInterceptor() invoked but Arez.isTaskInterceptorEnabled() ret...
@Test public void setTaskInterceptor_whenTaskInterceptorDisabled() { ArezTestUtil.disableTaskInterceptor(); final ArezContext context = Arez.context(); assertInvariantFailure( () -> context.setTaskInterceptor( SafeProcedure::call ), "Arez-0039: setTaskInterceptor() invoked but Arez.isTaskInterceptorEnabled() returns fa...
RoundBasedTaskExecutor { boolean runNextTask() { if ( 0 == _remainingTasksInCurrentRound ) { final int pendingTaskCount = getPendingTaskCount(); if ( 0 == pendingTaskCount ) { _currentRound = 0; return false; } else if ( _currentRound + 1 > _maxRounds ) { _currentRound = 0; onRunawayTasksDetected(); return false; } els...
@Test public void runNextTask() { final ArezContext context = Arez.context(); final TaskQueue taskQueue = context.getTaskQueue(); final RoundBasedTaskExecutor executor = new RoundBasedTaskExecutor( taskQueue, 2 ); final AtomicInteger task1CallCount = new AtomicInteger(); final AtomicInteger task2CallCount = new AtomicI...
RoundBasedTaskExecutor { void runTasks() { while ( true ) { if ( !runNextTask() ) { break; } } } RoundBasedTaskExecutor( @Nonnull final TaskQueue taskQueue, final int maxRounds ); }
@Test public void runTasks() { final ArezContext context = Arez.context(); final TaskQueue taskQueue = context.getTaskQueue(); final RoundBasedTaskExecutor executor = new RoundBasedTaskExecutor( taskQueue, 2 ); final AtomicInteger task1CallCount = new AtomicInteger(); final AtomicInteger task2CallCount = new AtomicInte...
SpyImpl implements Spy { @Override public boolean isTransactionActive() { return getContext().isTransactionActive(); } SpyImpl( @Nullable final ArezContext context ); @Override void addSpyEventHandler( @Nonnull final SpyEventHandler handler ); @Override void removeSpyEventHandler( @Nonnull final SpyEventHandler handler...
@Test public void isTransactionActive() { final ArezContext context = Arez.context(); final Spy spy = context.getSpy(); assertFalse( spy.isTransactionActive() ); setupReadOnlyTransaction( context ); assertTrue( spy.isTransactionActive() ); }
SpyImpl implements Spy { @Nonnull @Override public TransactionInfo getTransaction() { if ( Arez.shouldCheckApiInvariants() ) { apiInvariant( this::isTransactionActive, () -> "Arez-0105: Spy.getTransaction() invoked but no transaction active." ); } return getContext().getTransaction().asInfo(); } SpyImpl( @Nullable fina...
@Test public void getTransaction() { final ArezContext context = Arez.context(); final Spy spy = context.getSpy(); final String name = ValueUtil.randomString(); context.safeAction( name, () -> { observeADependency(); assertEquals( spy.getTransaction().getName(), name ); } ); }
SpyImpl implements Spy { @Nullable @Override public ComponentInfo findComponent( @Nonnull final String type, @Nonnull final Object id ) { final Component component = getContext().findComponent( type, id ); return null != component ? component.asInfo() : null; } SpyImpl( @Nullable final ArezContext context ); @Override ...
@Test public void findComponent_nativeComponentsDisabled() { ArezTestUtil.disableNativeComponents(); final ArezContext context = Arez.context(); final Spy spy = context.getSpy(); final String type = ValueUtil.randomString(); final String id = ValueUtil.randomString(); assertInvariantFailure( () -> spy.findComponent( ty...
SpyImpl implements Spy { @Nonnull @Override public Collection<ComponentInfo> findAllComponentsByType( @Nonnull final String type ) { final List<ComponentInfo> infos = getContext().findAllComponentsByType( type ).stream(). map( Component::asInfo ). collect( Collectors.toList() ); return Collections.unmodifiableCollectio...
@Test public void findAllComponentsByType_nativeComponentsDisabled() { ArezTestUtil.disableNativeComponents(); final ArezContext context = Arez.context(); final Spy spy = context.getSpy(); final String type = ValueUtil.randomString(); assertInvariantFailure( () -> spy.findAllComponentsByType( type ), "Arez-0011: ArezCo...
SpyImpl implements Spy { @Nonnull @Override public Collection<TaskInfo> findAllTopLevelTasks() { return TaskInfoImpl.asUnmodifiableInfos( getContext().getTopLevelTasks().values() ); } SpyImpl( @Nullable final ArezContext context ); @Override void addSpyEventHandler( @Nonnull final SpyEventHandler handler ); @Override v...
@Test public void findAllTopLevelTasks() { final ArezContext context = Arez.context(); final Task task = context.task( ValueUtil::randomString ); final Spy spy = context.getSpy(); final Collection<TaskInfo> values = spy.findAllTopLevelTasks(); assertEquals( values.size(), 1 ); assertEquals( values.iterator().next().get...
ComputableValueInfoImpl implements ComputableValueInfo { @Nonnull @Override public String getName() { return _computableValue.getName(); } ComputableValueInfoImpl( @Nonnull final ComputableValue<?> computableValue ); @Nonnull @Override String getName(); @Override boolean isComputing(); @Nonnull @Override Priority getPr...
@Test public void getTransactionComputing_missingTracker() { final ArezContext context = Arez.context(); final ComputableValue<String> computableValue = context.computable( () -> "" ); computableValue.setComputing( true ); final ComputableValueInfoImpl info = (ComputableValueInfoImpl) computableValue.asInfo(); setupRea...
SpyImpl implements Spy { @Nonnull @Override public Collection<ObservableValueInfo> findAllTopLevelObservableValues() { return ObservableValueInfoImpl.asUnmodifiableInfos( getContext().getTopLevelObservables().values() ); } SpyImpl( @Nullable final ArezContext context ); @Override void addSpyEventHandler( @Nonnull final...
@Test public void findAllTopLevelObservables() { final ArezContext context = Arez.context(); final ObservableValue<String> observableValue = context.observable(); final Spy spy = context.getSpy(); final Collection<ObservableValueInfo> values = spy.findAllTopLevelObservableValues(); assertEquals( values.size(), 1 ); ass...
SpyImpl implements Spy { @Nonnull @Override public Collection<ComputableValueInfo> findAllTopLevelComputableValues() { return ComputableValueInfoImpl.asUnmodifiableInfos( getContext().getTopLevelComputableValues().values() ); } SpyImpl( @Nullable final ArezContext context ); @Override void addSpyEventHandler( @Nonnull ...
@Test public void findAllTopLevelComputableValues() { final ArezContext context = Arez.context(); final ComputableValue<String> computableValue = context.computable( () -> "" ); final Spy spy = context.getSpy(); final Collection<ComputableValueInfo> values = spy.findAllTopLevelComputableValues(); assertEquals( values.s...
SpyImpl implements Spy { @Nonnull @Override public Collection<ObserverInfo> findAllTopLevelObservers() { return ObserverInfoImpl.asUnmodifiableInfos( getContext().getTopLevelObservers().values() ); } SpyImpl( @Nullable final ArezContext context ); @Override void addSpyEventHandler( @Nonnull final SpyEventHandler handle...
@Test public void findAllTopLevelObservers() { final ArezContext context = Arez.context(); final Observer observer = context.observer( AbstractTest::observeADependency ); final Spy spy = context.getSpy(); final Collection<ObserverInfo> values = spy.findAllTopLevelObservers(); assertEquals( values.size(), 1 ); assertEqu...
SpyImpl implements Spy { @Nonnull @Override public <T> ObservableValueInfo asObservableValueInfo( @Nonnull final ObservableValue<T> observableValue ) { return observableValue.asInfo(); } SpyImpl( @Nullable final ArezContext context ); @Override void addSpyEventHandler( @Nonnull final SpyEventHandler handler ); @Overrid...
@Test public void observable_getValue_noAccessor() { final ArezContext context = Arez.context(); final Spy spy = context.getSpy(); final ObservableValue<Integer> observableValue = context.observable(); assertInvariantFailure( () -> context.action( () -> spy.asObservableValueInfo( observableValue ).getValue() ), "Arez-0...
SpyImpl implements Spy { @Nonnull @Override public ComponentInfo asComponentInfo( @Nonnull final Component component ) { return component.asInfo(); } SpyImpl( @Nullable final ArezContext context ); @Override void addSpyEventHandler( @Nonnull final SpyEventHandler handler ); @Override void removeSpyEventHandler( @Nonnul...
@Test public void asComponentInfo() { final ArezContext context = Arez.context(); final Component component = context.component( ValueUtil.randomString(), ValueUtil.randomString() ); final ComponentInfo info = context.getSpy().asComponentInfo( component ); assertEquals( info.getName(), component.getName() ); }
SpyImpl implements Spy { @Nonnull @Override public ObserverInfo asObserverInfo( @Nonnull final Observer observer ) { return observer.asInfo(); } SpyImpl( @Nullable final ArezContext context ); @Override void addSpyEventHandler( @Nonnull final SpyEventHandler handler ); @Override void removeSpyEventHandler( @Nonnull fin...
@Test public void asObserverInfo() { final ArezContext context = Arez.context(); final Observer observer = context.observer( AbstractTest::observeADependency ); final ObserverInfo info = context.getSpy().asObserverInfo( observer ); assertEquals( info.getName(), observer.getName() ); }
SpyImpl implements Spy { @Nonnull @Override public TaskInfo asTaskInfo( @Nonnull final Task task ) { return task.asInfo(); } SpyImpl( @Nullable final ArezContext context ); @Override void addSpyEventHandler( @Nonnull final SpyEventHandler handler ); @Override void removeSpyEventHandler( @Nonnull final SpyEventHandler h...
@Test public void asTaskInfo() { final ArezContext context = Arez.context(); final Task task = context.task( ValueUtil::randomString ); final TaskInfo info = context.getSpy().asTaskInfo( task ); assertEquals( info.getName(), task.getName() ); }
SpyImpl implements Spy { @Nonnull @Override public <T> ComputableValueInfo asComputableValueInfo( @Nonnull final ComputableValue<T> computableValue ) { return computableValue.asInfo(); } SpyImpl( @Nullable final ArezContext context ); @Override void addSpyEventHandler( @Nonnull final SpyEventHandler handler ); @Overrid...
@Test public void asComputableValueInfo() { final ArezContext context = Arez.context(); final ComputableValue<String> computableValue = context.computable( () -> "" ); final ComputableValueInfo info = context.getSpy().asComputableValueInfo( computableValue ); assertEquals( info.getName(), computableValue.getName() ); }
ObserverErrorHandlerSupport implements ObserverErrorHandler { void addObserverErrorHandler( @Nonnull final ObserverErrorHandler handler ) { if ( Arez.shouldCheckApiInvariants() ) { apiInvariant( () -> !_handlers.contains( handler ), () -> "Arez-0096: Attempting to add handler " + handler + " that is already in " + "the...
@Test public void addObserverErrorHandler_alreadyExists() { final ObserverErrorHandlerSupport support = new ObserverErrorHandlerSupport(); final ObserverErrorHandler handler = ( observerArg, errorArg, throwableArg ) -> { }; support.addObserverErrorHandler( handler ); assertInvariantFailure( () -> support.addObserverErr...
ComputableValueInfoImpl implements ComputableValueInfo { @Nonnull @Override public List<ObservableValueInfo> getDependencies() { if ( _computableValue.isComputing() ) { final Transaction transaction = getTransactionComputing(); final List<ObservableValue<?>> observableValues = transaction.getObservableValues(); if ( nu...
@Test public void getDependencies() { final ArezContext context = Arez.context(); final ComputableValue<String> computableValue = context.computable( () -> "" ); final ComputableValueInfo info = computableValue.asInfo(); assertEquals( info.getDependencies().size(), 0 ); final ObservableValue<?> observableValue = contex...
ObserverErrorHandlerSupport implements ObserverErrorHandler { void removeObserverErrorHandler( @Nonnull final ObserverErrorHandler handler ) { if ( Arez.shouldCheckApiInvariants() ) { apiInvariant( () -> _handlers.contains( handler ), () -> "Arez-0097: Attempting to remove handler " + handler + " that is not in " + "th...
@Test public void removeObserverErrorHandler_noExists() { final ObserverErrorHandlerSupport support = new ObserverErrorHandlerSupport(); final ObserverErrorHandler handler = ( observerArg, errorArg, throwableArg ) -> { }; assertInvariantFailure( () -> support.removeObserverErrorHandler( handler ), "Arez-0097: Attemptin...
Task extends Node { public void schedule() { if ( isIdle() ) { queueTask(); } getContext().triggerScheduler(); } Task( @Nullable final ArezContext context, @Nullable final String name, @Nonnull final SafeProcedure work, final int flags ); void schedule(); @Override void dispose(); @Override bool...
@Test public void schedule() { final AtomicInteger callCount = new AtomicInteger(); final Task task = Arez.context().task( callCount::incrementAndGet ); assertEquals( callCount.get(), 1 ); assertTrue( task.isIdle() ); task.schedule(); assertEquals( callCount.get(), 2 ); }
Task extends Node { void markAsQueued() { if ( Arez.shouldCheckInvariants() ) { invariant( this::isIdle, () -> "Arez-0128: Attempting to queue task named '" + getName() + "' when task is not idle." ); } _flags = Flags.setState( _flags, Flags.STATE_QUEUED ); } Task( @Nullable final ArezContext context, @Nullable...
@Test public void markAsQueued_alreadyScheduled() { final Task task = new Task( Arez.context(), "X", ValueUtil::randomString, 0 ); task.markAsQueued(); assertInvariantFailure( task::markAsQueued, "Arez-0128: Attempting to queue task named 'X' when task is not idle." ); }
Task extends Node { Task( @Nullable final ArezContext context, @Nullable final String name, @Nonnull final SafeProcedure work, final int flags ) { super( context, name ); if ( Arez.shouldCheckApiInvariants() ) { apiInvariant( () -> ( ~Flags.CONFIG_FLAGS_MASK & flags ) == 0, () -> "Arez-0224: Task named '" + name + "' p...
@Test public void asInfo_spyDisabled() { ArezTestUtil.disableSpies(); final Task task = Arez.context().task( ValueUtil::randomString ); assertInvariantFailure( task::asInfo, "Arez-0130: Task.asInfo() invoked but Arez.areSpiesEnabled() returned false." ); }
Task extends Node { @Nonnull Priority getPriority() { return Priority.values()[ getPriorityIndex() ]; } Task( @Nullable final ArezContext context, @Nullable final String name, @Nonnull final SafeProcedure work, final int flags ); void schedule(); @Override void dispose(); @Override boolean isDis...
@Test public void getPriority() { assertEquals( Task.Flags.getPriorityIndex( Task.Flags.PRIORITY_HIGHEST | Task.Flags.STATE_QUEUED ), 0 ); assertEquals( Task.Flags.getPriorityIndex( Task.Flags.PRIORITY_HIGH | Task.Flags.STATE_QUEUED ), 1 ); assertEquals( Task.Flags.getPriorityIndex( Task.Flags.PRIORITY_NORMAL | Task.Fl...
ActionFlags { static boolean isVerifyActionRuleValid( final int flags ) { return VERIFY_ACTION_REQUIRED == ( flags & VERIFY_ACTION_MASK ) || NO_VERIFY_ACTION_REQUIRED == ( flags & VERIFY_ACTION_MASK ); } private ActionFlags(); static final int READ_ONLY; static final int READ_WRITE; static final int NO_REPORT_RESULT;...
@Test public void isVerifyActionRuleValid() { assertTrue( ActionFlags.isVerifyActionRuleValid( ActionFlags.VERIFY_ACTION_REQUIRED ) ); assertTrue( ActionFlags.isVerifyActionRuleValid( ActionFlags.NO_VERIFY_ACTION_REQUIRED ) ); assertFalse( ActionFlags.isVerifyActionRuleValid( 0 ) ); assertFalse( ActionFlags.isVerifyAct...
ActionFlags { static int verifyActionRule( final int flags ) { return Arez.shouldCheckApiInvariants() ? 0 != ( flags & VERIFY_ACTION_MASK ) ? 0 : VERIFY_ACTION_REQUIRED : 0; } private ActionFlags(); static final int READ_ONLY; static final int READ_WRITE; static final int NO_REPORT_RESULT; static final int REQUIRE_NE...
@Test public void verifyActionRule() { assertEquals( ActionFlags.verifyActionRule( ActionFlags.VERIFY_ACTION_REQUIRED ), 0 ); assertEquals( ActionFlags.verifyActionRule( ActionFlags.NO_VERIFY_ACTION_REQUIRED ), 0 ); assertEquals( ActionFlags.verifyActionRule( 0 ), ActionFlags.VERIFY_ACTION_REQUIRED ); assertEquals( Act...
Transaction { long getStartedAt() { if ( Arez.shouldCheckInvariants() ) { invariant( Arez::areSpiesEnabled, () -> "Arez-0134: Transaction.getStartedAt() invoked when Arez.areSpiesEnabled() is false" ); } return _startedAt; } Transaction( @Nullable final ArezContext context, @Nullable final Transaction pr...
@Test public void construction_whenSpyDisabled() { ArezTestUtil.disableSpies(); final Transaction transaction = new Transaction( Arez.context(), null, ValueUtil.randomString(), false, null, false ); ArezTestUtil.enableSpies(); assertEquals( transaction.getStartedAt(), 0 ); }
Transaction { static Transaction begin( @Nonnull final ArezContext context, @Nullable final String name, final boolean mutation, @Nullable final Observer tracker ) { if ( Arez.shouldCheckApiInvariants() && Arez.shouldEnforceTransactionType() ) { if ( null != c_transaction ) { final boolean inComputableTransaction = nul...
@Test public void begin() { final ArezContext context = Arez.context(); final Observer tracker = context.computable( () -> "" ).getObserver(); final Transaction transaction = new Transaction( context, null, ValueUtil.randomString(), false, tracker, false ); Transaction.setTransaction( transaction ); assertEquals( track...
Transaction { static void commit( @Nonnull final Transaction transaction ) { if ( Arez.shouldCheckInvariants() ) { invariant( () -> null != c_transaction, () -> "Arez-0122: Attempting to commit transaction named '" + transaction.getName() + "' but no transaction is active." ); assert null != c_transaction; invariant( (...
@Test public void commit() { final ArezContext context = Arez.context(); final ComputableValue<String> computableValue = context.computable( () -> "" ); final Observer tracker = computableValue.getObserver(); ensureDerivationHasObserver( tracker ); final Transaction transaction = new Transaction( context, null, ValueUt...
ComputableValueInfoImpl implements ComputableValueInfo { @Nullable @Override public ComponentInfo getComponent() { if ( Arez.shouldCheckInvariants() ) { invariant( Arez::areNativeComponentsEnabled, () -> "Arez-0109: Spy.getComponent invoked when Arez.areNativeComponentsEnabled() returns false." ); } final Component com...
@Test public void getComponent_ComputableValue_nativeComponentsDisabled() { ArezTestUtil.disableNativeComponents(); final ArezContext context = Arez.context(); final ComputableValue<Object> computableValue = context.computable( () -> "" ); assertInvariantFailure( () -> computableValue.asInfo().getComponent(), "Arez-010...
Transaction { void beginTracking() { if ( null != _tracker ) { if ( Arez.shouldCheckInvariants() ) { _tracker.invariantDependenciesBackLink( "Pre beginTracking" ); } if ( !_tracker.isDisposing() ) { _tracker.setState( Observer.Flags.STATE_UP_TO_DATE ); } _tracker.markDependenciesLeastStaleObserverAsUpToDate(); } } Tran...
@Test public void beginTracking() { final ArezContext context = Arez.context(); final Observer tracker = context.computable( () -> "" ).getObserver(); final Transaction transaction = new Transaction( context, null, ValueUtil.randomString(), false, tracker, false ); Transaction.setTransaction( transaction ); ensureDeriv...
Transaction { void observe( @Nonnull final ObservableValue<?> observableValue ) { if ( Arez.shouldCheckInvariants() ) { markTransactionAsUsed(); invariant( observableValue::isNotDisposed, () -> "Arez-0142: Invoked observe on transaction named '" + getName() + "' for observableValue " + "named '" + observableValue.getNa...
@Test public void observe() { final ArezContext context = Arez.context(); final Observer tracker = context.computable( () -> "" ).getObserver(); final Transaction transaction = new Transaction( context, null, ValueUtil.randomString(), false, tracker, false ); Transaction.setTransaction( transaction ); transaction.begin...
Transaction { @Nonnull String getName() { if ( Arez.shouldCheckInvariants() ) { invariant( Arez::areNamesEnabled, () -> "Arez-0133: Transaction.getName() invoked when Arez.areNamesEnabled() is false" ); } assert null != _name; return _name; } Transaction( @Nullable final ArezContext context, @Nullable fi...
@Test public void processPendingDeactivations_calledOnNonRootTransaction() { final ArezContext context = Arez.context(); final Transaction transaction1 = new Transaction( context, null, ValueUtil.randomString(), false, null, false ); final Transaction transaction2 = new Transaction( context, transaction1, ValueUtil.ran...
Transaction { void verifyWriteAllowed( @Nonnull final ObservableValue<?> observableValue ) { if ( Arez.shouldEnforceTransactionType() && Arez.shouldCheckInvariants() ) { if ( isComputableValueTracker() ) { invariant( () -> observableValue.isComputableValue() && observableValue.getObserver() == _tracker, () -> "Arez-015...
@Test public void verifyWriteAllowed_withReadOnlyTransaction_enforceTransactionType_set_to_false() { ArezTestUtil.noEnforceTransactionType(); final ArezContext context = Arez.context(); final Transaction transaction = new Transaction( context, null, ValueUtil.randomString(), false, null, false ); final ObservableValue<...
Transaction { void reportChangeConfirmed( @Nonnull final ObservableValue<?> observableValue ) { if ( Arez.shouldCheckInvariants() ) { invariant( observableValue::isNotDisposed, () -> "Arez-0149: Invoked reportChangeConfirmed on transaction named '" + getName() + "' for ObservableValue named '" + observableValue.getName...
@Test public void reportChangeConfirmed_singleUpToDateObserver() { final ArezContext context = Arez.context(); final Observer calculator = context.computable( () -> "" ).getObserver(); setCurrentTransaction( calculator ); calculator.setState( Observer.Flags.STATE_UP_TO_DATE ); final ObservableValue<?> observableValue =...
Transaction { @Nonnull static Transaction current() { if ( Arez.shouldCheckInvariants() ) { invariant( () -> null != c_transaction, () -> "Arez-0117: Attempting to get current transaction but no transaction is active." ); } assert null != c_transaction; return c_transaction; } Transaction( @Nullable final ArezContext c...
@Test public void current() { final ArezContext context = Arez.context(); final Transaction transaction = new Transaction( context, null, ValueUtil.randomString(), false, null, false ); transaction.begin(); Transaction.setTransaction( transaction ); assertEquals( Transaction.current(), transaction ); }
Transaction { static boolean isTransactionActive( @Nonnull final ArezContext context ) { return null != c_transaction && ( !Arez.areZonesEnabled() || c_transaction.getContext() == context ); } Transaction( @Nullable final ArezContext context, @Nullable final Transaction previous, @Nullable...
@Test public void isTransactionActive() { final ArezContext context = Arez.context(); final Transaction transaction = new Transaction( context, null, ValueUtil.randomString(), false, null, false ); transaction.begin(); assertFalse( Transaction.isTransactionActive( context ) ); Transaction.setTransaction( transaction );...
Transaction { void reportDispose( @Nonnull final Disposable disposable ) { if ( Arez.shouldCheckInvariants() ) { invariant( disposable::isNotDisposed, () -> "Arez-0176: Invoked reportDispose on transaction named '" + getName() + "' where the element is disposed." ); invariant( () -> !Arez.shouldEnforceTransactionType()...
@Test public void reportDispose() { final Transaction transaction = new Transaction( Arez.context(), null, ValueUtil.randomString(), true, null, false ); final MyDisposable node = new MyDisposable(); transaction.reportDispose( node ); node.dispose(); assertInvariantFailure( () -> transaction.reportDispose( node ), "Are...
ComputableValueInfoImpl implements ComputableValueInfo { @Override public boolean isActive() { return _computableValue.getObserver().isActive(); } ComputableValueInfoImpl( @Nonnull final ComputableValue<?> computableValue ); @Nonnull @Override String getName(); @Override boolean isComputing(); @Nonnull @Override Priori...
@Test public void isActive() { final ArezContext context = Arez.context(); final Spy spy = context.getSpy(); final ComputableValue<String> computableValue = context.computable( () -> "" ); assertFalse( spy.asComputableValueInfo( computableValue ).isActive() ); setupReadOnlyTransaction( context ); computableValue.getObs...
Arez { @Nonnull public static ArezContext context() { return areZonesEnabled() ? ZoneHolder.context() : ArezContextHolder.context(); } private Arez(); @OmitSymbol static boolean areZonesEnabled(); @OmitSymbol static boolean areNamesEnabled(); @OmitSymbol static boolean isVerifyEnabled(); @OmitSymbol static boolean are...
@Test public void context_when_zones_disabled() { ArezTestUtil.disableZones(); final ArezContext context1 = Arez.context(); assertNotNull( context1 ); final ArezContext context2 = Arez.context(); assertSame( context1, context2 ); }
Arez { @OmitSymbol( unless = "arez.enable_zones" ) static void activateZone( @Nonnull final Zone zone ) { ZoneHolder.activateZone( zone ); } private Arez(); @OmitSymbol static boolean areZonesEnabled(); @OmitSymbol static boolean areNamesEnabled(); @OmitSymbol static boolean isVerifyEnabled(); @OmitSymbol static boole...
@Test public void activateZone_whenZonesNotEnabled() { ArezTestUtil.disableZones(); assertInvariantFailure( () -> Arez.activateZone( new Zone() ), "Arez-0002: Invoked Arez.activateZone() but zones are not enabled." ); }
Arez { @OmitSymbol( unless = "arez.enable_zones" ) static void deactivateZone( @Nonnull final Zone zone ) { ZoneHolder.deactivateZone( zone ); } private Arez(); @OmitSymbol static boolean areZonesEnabled(); @OmitSymbol static boolean areNamesEnabled(); @OmitSymbol static boolean isVerifyEnabled(); @OmitSymbol static b...
@Test public void deactivateZone_whenZonesNotEnabled() { ArezTestUtil.disableZones(); assertInvariantFailure( () -> Arez.deactivateZone( new Zone() ), "Arez-0003: Invoked Arez.deactivateZone() but zones are not enabled." ); } @Test public void deactivateZone_whenNotActive() { ArezTestUtil.enableZones(); assertInvariant...
TransactionInfoImpl implements TransactionInfo { @Nonnull @Override public String getName() { return getTransaction().getName(); } TransactionInfoImpl( @Nonnull final Transaction transaction ); @Nonnull @Override String getName(); @Override boolean isReadOnly(); @Nullable @Override TransactionInfo getParent(); @Overrid...
@Test public void getTracker_whenNoTracker() { final ArezContext context = Arez.context(); final Transaction transaction = new Transaction( context, null, ValueUtil.randomString(), true, null, false ); final TransactionInfo info = transaction.asInfo(); assertInvariantFailure( info::getTracker, "Invoked getTracker on Tr...
TaskInfoImpl implements TaskInfo { @Override public int hashCode() { return _task.hashCode(); } TaskInfoImpl( @Nonnull final Task task ); @Nonnull @Override String getName(); @Override boolean isIdle(); @Override boolean isScheduled(); @Nonnull @Override Priority getPriority(); @Override boolean isDisposed(); @Override...
@Test public void equalsAndHashCode() { final ArezContext context = Arez.context(); final Task task1 = context.task( ValueUtil::randomString ); final Task task2 = context.task( ValueUtil::randomString ); final TaskInfo info1a = task1.asInfo(); final TaskInfo info1b = new TaskInfoImpl( task1 ); final TaskInfo info2 = ta...
ObservableValueInfoImpl implements ObservableValueInfo { @Override public ComputableValueInfo asComputableValue() { return _observableValue.getObserver().getComputableValue().asInfo(); } ObservableValueInfoImpl( @Nonnull final ObservableValue<?> observableValue ); @Nonnull @Override String getName(); @Override boolean ...
@Test public void asComputableValue() { final ArezContext context = Arez.context(); final String name = ValueUtil.randomString(); final ComputableValue<String> computableValue = context.computable( name, () -> "" ); final ObservableValue<String> observableValue = computableValue.getObservableValue(); final ObservableVa...
ObservableValueInfoImpl implements ObservableValueInfo { @Override public int hashCode() { return _observableValue.hashCode(); } ObservableValueInfoImpl( @Nonnull final ObservableValue<?> observableValue ); @Nonnull @Override String getName(); @Override boolean isComputableValue(); @Override ComputableValueInfo asCompu...
@SuppressWarnings( "EqualsWithItself" ) @Test public void equalsAndHashCode() { final ArezContext context = Arez.context(); final ObservableValue<Object> observableValue1 = context.observable(); final ObservableValue<Object> observableValue2 = context.observable(); final ObservableValueInfo info1a = observableValue1.as...
ObservableValueInfoImpl implements ObservableValueInfo { @Override public boolean isComputableValue() { return _observableValue.isComputableValue(); } ObservableValueInfoImpl( @Nonnull final ObservableValue<?> observableValue ); @Nonnull @Override String getName(); @Override boolean isComputableValue(); @Override Compu...
@Test public void isComputableValue() { final ArezContext context = Arez.context(); final Spy spy = context.getSpy(); assertTrue( spy.asObservableValueInfo( context.computable( () -> "" ).getObservableValue() ).isComputableValue() ); assertFalse( spy.asObservableValueInfo( context.observable() ).isComputableValue() ); ...
ObservableValueInfoImpl implements ObservableValueInfo { @Nullable @Override public ComponentInfo getComponent() { if ( Arez.shouldCheckInvariants() ) { invariant( Arez::areNativeComponentsEnabled, () -> "Arez-0107: Spy.getComponent invoked when Arez.areNativeComponentsEnabled() returns false." ); } final Component com...
@Test public void getComponent_Observable_nativeComponentsDisabled() { ArezTestUtil.disableNativeComponents(); final ArezContext context = Arez.context(); final ObservableValue<Object> value = context.observable(); assertInvariantFailure( () -> value.asInfo().getComponent(), "Arez-0107: Spy.getComponent invoked when Ar...
ComputableValueInfoImpl implements ComputableValueInfo { @Nonnull @Override public List<ObserverInfo> getObservers() { return ObserverInfoImpl.asUnmodifiableInfos( _computableValue.getObservableValue().getObservers() ); } ComputableValueInfoImpl( @Nonnull final ComputableValue<?> computableValue ); @Nonnull @Override S...
@Test public void getObservers() { final ArezContext context = Arez.context(); final Spy spy = context.getSpy(); final ComputableValue<?> computableValue = context.computable( () -> "" ); assertEquals( spy.asComputableValueInfo( computableValue ).getObservers().size(), 0 ); final Observer observer = context.observer( n...
SpyEventHandlerSupport { void removeSpyEventHandler( @Nonnull final SpyEventHandler handler ) { if ( Arez.shouldCheckApiInvariants() ) { apiInvariant( () -> _spyEventHandlers.contains( handler ), () -> "Arez-0103: Attempting to remove handler " + handler + " that is not " + "in the list of spy handlers." ); } _spyEvent...
@Test public void removeSpyEventHandler_noExists() { final SpyEventHandlerSupport support = new SpyEventHandlerSupport(); final SpyEventHandler handler = new TestSpyEventHandler( Arez.context() ); assertInvariantFailure( () -> support.removeSpyEventHandler( handler ), "Arez-0103: Attempting to remove handler " + handle...
ObservableValueInfoImpl implements ObservableValueInfo { @Nullable @Override public Object getValue() throws Throwable { if ( Arez.shouldCheckInvariants() ) { invariant( Arez::arePropertyIntrospectorsEnabled, () -> "Arez-0111: Spy.getValue invoked when Arez.arePropertyIntrospectorsEnabled() returns false." ); } final P...
@Test public void observable_getValue_introspectorsDisabled() { ArezTestUtil.disablePropertyIntrospectors(); final ArezContext context = Arez.context(); final ObservableValue<Integer> computableValue1 = context.observable(); assertInvariantFailure( () -> context.action( () -> computableValue1.asInfo().getValue() ), "Ar...
ObservableValueInfoImpl implements ObservableValueInfo { @Override public boolean hasAccessor() { if ( Arez.shouldCheckInvariants() ) { invariant( Arez::arePropertyIntrospectorsEnabled, () -> "Arez-0110: Spy.hasAccessor invoked when Arez.arePropertyIntrospectorsEnabled() returns false." ); } return null != _observableV...
@Test public void observable_hasAccessor_introspectorsDisabled() { ArezTestUtil.disablePropertyIntrospectors(); final ArezContext context = Arez.context(); final ObservableValue<Integer> observableValue = context.observable(); assertInvariantFailure( () -> context.action( () -> observableValue.asInfo().hasAccessor() ),...
ObservableValueInfoImpl implements ObservableValueInfo { @Override public boolean hasMutator() { if ( Arez.shouldCheckInvariants() ) { invariant( Arez::arePropertyIntrospectorsEnabled, () -> "Arez-0113: Spy.hasMutator invoked when Arez.arePropertyIntrospectorsEnabled() returns false." ); } return null != _observableVal...
@Test public void observable_hasMutator_introspectorsDisabled() { ArezTestUtil.disablePropertyIntrospectors(); final ArezContext context = Arez.context(); final ObservableValue<Integer> observableValue = context.observable(); assertInvariantFailure( () -> context.action( () -> observableValue.asInfo().hasMutator() ), "...
ObservableValueInfoImpl implements ObservableValueInfo { @SuppressWarnings( { "unchecked", "rawtypes" } ) @Override public void setValue( @Nullable final Object value ) throws Throwable { if ( Arez.shouldCheckInvariants() ) { invariant( Arez::arePropertyIntrospectorsEnabled, () -> "Arez-0114: Spy.setValue invoked when ...
@Test public void observable_setValue_introspectorsDisabled() { ArezTestUtil.disablePropertyIntrospectors(); final ArezContext context = Arez.context(); final ObservableValue<Integer> observableValue = context.observable(); assertInvariantFailure( () -> context.action( () -> observableValue.asInfo().setValue( 44 ) ), "...
ComputableValue extends Node { @Nonnull Observer getObserver() { return _observer; } ComputableValue( @Nullable final ArezContext context, @Nullable final Component component, @Nullable final String name, @Nonnull final SafeFunction<T> function, ...
@Test public void highPriorityComputableValue() { final ComputableValue<String> computableValue = Arez.context().computable( () -> "", ComputableValue.Flags.PRIORITY_HIGH ); assertEquals( computableValue.getObserver().getTask().getPriority(), Priority.HIGH ); }
ComputableValue extends Node { T computeValue() { if ( Arez.shouldCheckInvariants() ) { _computing = true; } try { return _function.call(); } finally { if ( Arez.shouldCheckInvariants() ) { _computing = false; } } } ComputableValue( @Nullable final ArezContext context, @Nullable final Component compo...
@Test public void computeValue() { final ArezContext context = Arez.context(); final AtomicReference<String> value = new AtomicReference<>(); final AtomicReference<ComputableValue<String>> ref = new AtomicReference<>(); value.set( "" ); final SafeFunction<String> function = () -> { observeADependency(); assertTrue( ref...
ComputableValue extends Node { void compute() { final T oldValue = _value; try { final T newValue = computeValue(); if ( !Objects.equals( oldValue, newValue ) ) { _value = newValue; _error = null; getObservableValue().reportChangeConfirmed(); } if ( Arez.shouldCheckApiInvariants() ) { if ( getObserver().areArezDependen...
@Test public void compute() { final ArezContext context = Arez.context(); final String name = ValueUtil.randomString(); final AtomicReference<String> value = new AtomicReference<>(); final String value1 = ValueUtil.randomString(); final String value2 = ValueUtil.randomString(); final SafeFunction<String> function = () ...
ComputableValue extends Node { public T get() { if ( Arez.shouldCheckApiInvariants() ) { apiInvariant( () -> !_computing, () -> "Arez-0049: Detected a cycle deriving ComputableValue named '" + getName() + "'." ); apiInvariant( _observer::isNotDisposed, () -> "Arez-0050: ComputableValue named '" + getName() + "' accesse...
@Test public void compute_noDependencies() { ignoreObserverErrors(); final ArezContext context = Arez.context(); final ComputableValue<String> computableValue = context.computable( "XYZ", ValueUtil::randomString, ComputableValue.Flags.KEEPALIVE | ComputableValue.Flags.RUN_LATER ); assertInvariantFailure( () -> Arez.con...
ComputableValue extends Node { @Override public void dispose() { if ( isNotDisposed() ) { if ( Arez.shouldCheckInvariants() ) { getContext().safeAction( Arez.areNamesEnabled() ? getName() + ".dispose" : null, () -> getContext().getTransaction().reportDispose( this ), ActionFlags.NO_VERIFY_ACTION_REQUIRED ); } _disposed...
@Test public void dispose() { final ArezContext context = Arez.context(); final ComputableValue<String> computableValue = context.computable( () -> "" ); final Observer observer = computableValue.getObserver(); setCurrentTransaction( observer ); observer.setState( Observer.Flags.STATE_UP_TO_DATE ); assertFalse( observe...
ComputableValueInfoImpl implements ComputableValueInfo { @OmitSymbol( unless = "arez.enable_property_introspection" ) @Nullable @Override public Object getValue() throws Throwable { if ( Arez.shouldCheckInvariants() ) { invariant( Arez::arePropertyIntrospectorsEnabled, () -> "Arez-0116: Spy.getValue invoked when Arez.a...
@Test public void computableValue_introspection_noObservers() throws Throwable { final ArezContext context = Arez.context(); final ComputableValue<String> computableValue1 = context.computable( () -> { observeADependency(); return "42"; } ); assertNull( computableValue1.asInfo().getValue() ); } @Test public void comput...
ComputableValue extends Node { @SuppressWarnings( "ConstantConditions" ) @OmitSymbol( unless = "arez.enable_spies" ) @Nonnull ComputableValueInfo asInfo() { if ( Arez.shouldCheckInvariants() ) { invariant( Arez::areSpiesEnabled, () -> "Arez-0195: ComputableValue.asInfo() invoked but Arez.areSpiesEnabled() returned fals...
@Test public void asInfo() { final ArezContext context = Arez.context(); final SafeFunction<String> function = () -> { observeADependency(); return ""; }; final ComputableValue<String> computableValue = context.computable( function ); final ComputableValueInfo info = computableValue.asInfo(); assertEquals( info.getName...
ComputableValue extends Node { void incrementKeepAliveRefCount() { keepAliveInvariants(); _keepAliveRefCount++; if ( 1 == _keepAliveRefCount ) { final ObservableValue<T> observableValue = getObservableValue(); if ( !observableValue.isActive() ) { final ArezContext context = getContext(); if ( context.isTransactionActiv...
@Test public void incrementKeepAliveRefCount() { final ArezContext context = Arez.context(); final ObservableValue<Object> observable = context.observable(); final AtomicInteger calls = new AtomicInteger(); final SafeFunction<String> function = () -> { observable.reportObserved(); calls.incrementAndGet(); return ""; };...
ComputableValue extends Node { @OmitSymbol void setKeepAliveRefCount( final int keepAliveRefCount ) { _keepAliveRefCount = keepAliveRefCount; } ComputableValue( @Nullable final ArezContext context, @Nullable final Component component, @Nullable final String name, ...
@Test public void incrementKeepAliveRefCount_badInitialRefCount() { final ArezContext context = Arez.context(); final ObservableValue<Object> observable = context.observable(); final SafeFunction<String> function = () -> { observable.reportObserved(); return ""; }; final ComputableValue<String> computableValue = contex...
ComputableValue extends Node { void decrementKeepAliveRefCount() { _keepAliveRefCount--; keepAliveInvariants(); if ( 0 == _keepAliveRefCount ) { final ObservableValue<T> observableValue = getObservableValue(); final ArezContext context = getContext(); if ( context.isTransactionActive() ) { if ( !observableValue.isPendi...
@Test public void decrementKeepAliveRefCount() { final ArezContext context = Arez.context(); final ObservableValue<Object> observable = context.observable(); final AtomicInteger calls = new AtomicInteger(); final SafeFunction<String> function = () -> { observable.reportObserved(); calls.incrementAndGet(); return ""; };...
ComputableValue extends Node { @Nonnull public Disposable keepAlive() { if ( Arez.shouldCheckApiInvariants() ) { apiInvariant( () -> !getObserver().isKeepAlive(), () -> "Arez-0223: ComputableValue.keepAlive() was invoked on computable value named '" + getName() + "' but invoking this method when the computable value ha...
@Test public void keepAlive() { final ArezContext context = Arez.context(); final ObservableValue<Object> observable = context.observable(); final AtomicInteger calls = new AtomicInteger(); final SafeFunction<String> function = () -> { observable.reportObserved(); calls.incrementAndGet(); return ""; }; final Computable...
ArezProcessor extends AbstractStandardProcessor { @Nonnull @Override protected String getOptionPrefix() { return "arez"; } @Override boolean process( @Nonnull final Set<? extends TypeElement> annotations, @Nonnull final RoundEnvironment env ); }
@Test public void unresolvedComponent() { final JavaFileObject source1 = fixture( "unresolved/com/example/component/UnresolvedComponent.java" ); final List<JavaFileObject> inputs = Collections.singletonList( source1 ); assertFailedCompileResource( inputs, "ArezProcessor unable to process com.example.component.Unresolve...
ComputableValueInfoImpl implements ComputableValueInfo { @Override public int hashCode() { return _computableValue.hashCode(); } ComputableValueInfoImpl( @Nonnull final ComputableValue<?> computableValue ); @Nonnull @Override String getName(); @Override boolean isComputing(); @Nonnull @Override Priority getPriority(); ...
@SuppressWarnings( "EqualsWithItself" ) @Test public void equalsAndHashCode() { final ArezContext context = Arez.context(); final ComputableValue<Object> computableValue1 = context.computable( () -> "1" ); final ComputableValue<Object> computableValue2 = context.computable( () -> "2" ); final ComputableValueInfo info1a...
AggregateLocator implements Locator { @Nonnull Disposable registerLocator( @Nonnull final Locator locator ) { if ( Arez.shouldCheckApiInvariants() ) { apiInvariant( () -> !_locators.contains( locator ), () -> "Arez-0189: Attempting to register locator " + locator + " when the " + "Locator is already present." ); } _loc...
@Test public void registerLookup_duplicate() { final TypeBasedLocator locator1 = new TypeBasedLocator(); final AggregateLocator locator = new AggregateLocator(); locator.registerLocator( locator1 ); assertInvariantFailure( () -> locator.registerLocator( locator1 ), "Arez-0189: Attempting to register locator " + locator...
ComponentInfoImpl implements ComponentInfo { @Override public int hashCode() { return _component.hashCode(); } ComponentInfoImpl( @Nonnull final Component component ); @Nonnull @Override String getType(); @Nonnull @Override Object getId(); @Nonnull @Override String getName(); @Override List<ObservableValueInfo> getObse...
@Test public void equalsAndHashCode() { final ArezContext context = Arez.context(); final Component component1 = context.component( ValueUtil.randomString(), ValueUtil.randomString() ); final Component component2 = context.component( ValueUtil.randomString(), ValueUtil.randomString() ); final ComponentInfo info1a = com...
TaskQueue { void queueTask( @Nonnull final Task task ) { queueTask( task.getPriorityIndex(), task ); } @SuppressWarnings( { "unchecked", "rawtypes", "RedundantSuppression" } ) TaskQueue( final int priorityCount, final int initialCapacity ); }
@Test public void queueTask_badPriority() { final TaskQueue queue = new TaskQueue( 3, 10 ); final ArezContext context = Arez.context(); assertInvariantFailure( () -> queue.queueTask( -1, context.task( "A", ValueUtil::randomString ) ), "Arez-0215: Attempting to queue task named 'A' but passed an invalid priority -1." );...
TaskQueue { @Nonnull Collection<Task> clear() { final List<Task> tasks = new ArrayList<>(); for ( int i = 0; i < _buffers.length; i++ ) { final CircularBuffer<Task> buffer = _buffers[ i ]; Task task; while ( null != ( task = buffer.pop() ) ) { tasks.add( task ); task.markAsIdle(); } } return tasks; } @SuppressWarnings(...
@Test public void clear() { final ArezContext context = Arez.context(); final TaskQueue queue = context.getTaskQueue(); context.task( "A", ValueUtil::randomString, Task.Flags.RUN_LATER | Task.Flags.PRIORITY_HIGHEST ); context.task( "B", ValueUtil::randomString, Task.Flags.RUN_LATER | Task.Flags.PRIORITY_HIGH ); context...
ArezUtil { @Nonnull @OmitSymbol( unless = "arez.enable_names" ) static String safeGetString( @Nonnull final Supplier<String> message ) { try { return message.get(); } catch ( final Throwable t ) { return "Exception generated whilst attempting to get supplied message.\n" + throwableToString( t ); } } private ArezUtil()...
@Test public void safeGetString() { assertEquals( ArezUtil.safeGetString( () -> "My String" ), "My String" ); } @Test public void safeGetString_generatesError() { final String text = ArezUtil.safeGetString( () -> { throw new RuntimeException( "X" ); } ); assertTrue( text.startsWith( "Exception generated whilst attempti...
ObservableValue extends Node { @Override public void dispose() { if ( isNotDisposed() ) { getContext().safeAction( Arez.areNamesEnabled() ? getName() + ".dispose" : null, this::performDispose ); if ( isComputableValue() ) { getObserver().dispose(); } else { if ( willPropagateSpyEvents() ) { reportSpyEvent( new Observab...
@Test public void dispose() { final ArezContext context = Arez.context(); final ObservableValue<?> observableValue = context.observable(); final Observer observer = context.observer( new CountAndObserveProcedure() ); setCurrentTransaction( newReadWriteObserver( context ) ); observableValue.setLeastStaleObserverState( O...
ObservableValue extends Node { void addObserver( @Nonnull final Observer observer ) { if ( Arez.shouldCheckInvariants() ) { invariant( () -> getContext().isTransactionActive(), () -> "Arez-0065: Attempt to invoke addObserver on ObservableValue named '" + getName() + "' when there is no active transaction." ); invariant...
@Test public void addObserver() { final ArezContext context = Arez.context(); final Observer observer = context.observer( new CountAndObserveProcedure() ); setCurrentTransaction( observer ); final ObservableValue<?> observableValue = context.observable(); assertEquals( observableValue.getObservers().size(), 0 ); assert...
ObservableValue extends Node { void removeObserver( @Nonnull final Observer observer ) { if ( Arez.shouldCheckInvariants() ) { invariant( () -> getContext().isTransactionActive(), () -> "Arez-0069: Attempt to invoke removeObserver on ObservableValue named '" + getName() + "' " + "when there is no active transaction." )...
@Test public void removeObserver() { final ArezContext context = Arez.context(); final Observer observer = context.observer( new CountAndObserveProcedure() ); setCurrentTransaction( observer ); final ObservableValue<?> observableValue = context.observable(); assertEquals( observableValue.getObservers().size(), 0 ); ass...
ObservableValue extends Node { void setLeastStaleObserverState( final int leastStaleObserverState ) { if ( Arez.shouldCheckInvariants() ) { invariant( () -> getContext().isTransactionActive(), () -> "Arez-0074: Attempt to invoke setLeastStaleObserverState on ObservableValue named '" + getName() + "' when there is no ac...
@Test public void setLeastStaleObserverState() { final ArezContext context = Arez.context(); final Observer observer = context.observer( new CountAndObserveProcedure() ); final ObservableValue<?> observableValue = context.observable(); setCurrentTransaction( observer ); assertEquals( observableValue.getLeastStaleObserv...
ObservableValue extends Node { @Nonnull Observer getObserver() { assert null != _observer; return _observer; } ObservableValue( @Nullable final ArezContext context, @Nullable final Component component, @Nullable final String name, @Nullable final Observer observe...
@Test public void invariantOwner_badObservableLink() { ArezTestUtil.disableRegistries(); final ArezContext context = Arez.context(); setupReadOnlyTransaction( context ); final Observer observer = context.computable( () -> "" ).getObserver(); final ObservableValue<?> observableValue = new ObservableValue<>( context, nul...
ObservableValue extends Node { void invariantObserversLinked() { if ( Arez.shouldCheckInvariants() ) { getObservers().forEach( observer -> invariant( () -> observer.getDependencies().contains( this ), () -> "Arez-0077: ObservableValue named '" + getName() + "' has observer " + "named '" + observer.getName() + "' which ...
@Test public void invariantObserversLinked() { final Observer observer1 = Arez.context().observer( new CountAndObserveProcedure() ); final Observer observer2 = Arez.context().observer( new CountAndObserveProcedure() ); final Observer observer3 = Arez.context().observer( new CountAndObserveProcedure() ); setupReadWriteT...
ObservableValue extends Node { void queueForDeactivation() { if ( Arez.shouldCheckInvariants() ) { invariant( () -> getContext().isTransactionActive(), () -> "Arez-0071: Attempt to invoke queueForDeactivation on ObservableValue named '" + getName() + "' when there is no active transaction." ); invariant( this::canDeact...
@Test public void queueForDeactivation() { final ArezContext context = Arez.context(); setupReadOnlyTransaction( context ); final ComputableValue<String> computableValue = context.computable( () -> "" ); final Observer observer = computableValue.getObserver(); final ObservableValue<?> observableValue = computableValue....
ObservableValue extends Node { boolean isPendingDeactivation() { return _pendingDeactivation; } ObservableValue( @Nullable final ArezContext context, @Nullable final Component component, @Nullable final String name, @Nullable final Observer observer, ...
@Test public void queueForDeactivation_observableIsNotAbleToBeDeactivated() { final ArezContext context = Arez.context(); setupReadOnlyTransaction( context ); final ObservableValue<?> observableValue = context.observable(); assertFalse( observableValue.isPendingDeactivation() ); assertInvariantFailure( observableValue:...
ObservableValue extends Node { void resetPendingDeactivation() { _pendingDeactivation = false; } ObservableValue( @Nullable final ArezContext context, @Nullable final Component component, @Nullable final String name, @Nullable final Observer observer, ...
@Test public void resetPendingDeactivation() { final ArezContext context = Arez.context(); setupReadOnlyTransaction( context ); final ComputableValue<String> computableValue = context.computable( () -> "" ); final Observer observer = computableValue.getObserver(); final ObservableValue<?> observableValue = computableVa...
ObservableValue extends Node { boolean canDeactivate() { return isComputableValue() && !getObserver().isKeepAlive(); } ObservableValue( @Nullable final ArezContext context, @Nullable final Component component, @Nullable final String name, @Nullable final Observer...
@Test public void canDeactivate() { final ArezContext context = Arez.context(); final Observer randomObserver = context.observer( new CountAndObserveProcedure() ); setCurrentTransaction( randomObserver ); final ComputableValue<String> computableValue = context.computable( () -> "" ); final Observer observer = computabl...
ObservableValue extends Node { void deactivate() { if ( Arez.shouldCheckInvariants() ) { invariant( () -> getContext().isTransactionActive(), () -> "Arez-0060: Attempt to invoke deactivate on ObservableValue named '" + getName() + "' when there is no active transaction." ); invariant( this::canDeactivate, () -> "Arez-0...
@Test public void deactivate() { final ArezContext context = Arez.context(); setupReadOnlyTransaction( context ); final ComputableValue<String> computableValue = context.computable( () -> "" ); final Observer observer = computableValue.getObserver(); observer.setState( Observer.Flags.STATE_UP_TO_DATE ); final Observabl...
ObservableValue extends Node { void activate() { if ( Arez.shouldCheckInvariants() ) { invariant( () -> getContext().isTransactionActive(), () -> "Arez-0062: Attempt to invoke activate on ObservableValue named '" + getName() + "' when there is no active transaction." ); invariant( () -> null != _observer, () -> "Arez-0...
@Test public void activate() { final ArezContext context = Arez.context(); setupReadOnlyTransaction( context ); final ComputableValue<String> computableValue = context.computable( () -> "" ); final Observer observer = computableValue.getObserver(); observer.setState( Observer.Flags.STATE_INACTIVE ); final ObservableVal...
ObservableValue extends Node { public void reportObserved() { getContext().getTransaction().observe( this ); } ObservableValue( @Nullable final ArezContext context, @Nullable final Component component, @Nullable final String name, @Nullable final Observer observe...
@Test public void reportObserved() { final ArezContext context = Arez.context(); setupReadOnlyTransaction( context ); final ObservableValue<?> observableValue = context.observable(); assertNotEquals( observableValue.getLastTrackerTransactionId(), context.getTransaction().getId() ); assertEquals( context.getTransaction(...
ObservableValue extends Node { public void reportObservedIfTrackingTransactionActive() { if ( getContext().isTrackingTransactionActive() ) { reportObserved(); } } ObservableValue( @Nullable final ArezContext context, @Nullable final Component component, @Nullable final String name,...
@Test public void reportObservedIfTrackingTransactionActive() { final ArezContext context = Arez.context(); final ObservableValue<?> observableValue = context.observable(); observableValue.reportObservedIfTrackingTransactionActive(); context.safeAction( observableValue::reportObservedIfTrackingTransactionActive, Action...
ObservableValue extends Node { @OmitSymbol( unless = "arez.check_invariants" ) public void preReportChanged() { if ( Arez.shouldCheckInvariants() ) { getContext().getTransaction().preReportChanged( this ); } } ObservableValue( @Nullable final ArezContext context, @Nullable final Component component, ...
@Test public void preReportChanged() { final ArezContext context = Arez.context(); final Observer observer = newReadWriteObserver( context ); setCurrentTransaction( observer ); final ObservableValue<?> observableValue = context.observable(); observableValue.preReportChanged(); }
ObservableValue extends Node { void setWorkState( final int workState ) { _workState = workState; } ObservableValue( @Nullable final ArezContext context, @Nullable final Component component, @Nullable final String name, @Nullable final Observer observer, ...
@Test public void preReportChanged_onDisposedObservable() { final ArezContext context = Arez.context(); setCurrentTransaction( newReadWriteObserver( context ) ); final ObservableValue<?> observableValue = context.observable(); observableValue.setWorkState( ObservableValue.DISPOSED ); assertInvariantFailure( observableV...
ObservableValue extends Node { public void reportChanged() { if ( willPropagateSpyEvents() ) { reportSpyEvent( new ObservableValueChangeEvent( asInfo(), getObservableValue() ) ); } getContext().getTransaction().reportChanged( this ); } ObservableValue( @Nullable final ArezContext context, @Nullable f...
@Test public void reportChanged() { final ArezContext context = Arez.context(); final Observer observer = newReadWriteObserver( context ); setCurrentTransaction( observer ); observer.setState( Observer.Flags.STATE_UP_TO_DATE ); final ObservableValue<?> observableValue = context.observable(); observableValue.setLeastSta...
ObservableValue extends Node { void reportPossiblyChanged() { getContext().getTransaction().reportPossiblyChanged( this ); } ObservableValue( @Nullable final ArezContext context, @Nullable final Component component, @Nullable final String name, @Nullable final Ob...
@Test public void reportPossiblyChanged() { final ArezContext context = Arez.context(); final Observer observer = newReadWriteObserver( context ); setCurrentTransaction( observer ); observer.setState( Observer.Flags.STATE_UP_TO_DATE ); final ComputableValue<String> computableValue = context.computable( () -> "" ); fina...
ObservableValue extends Node { void reportChangeConfirmed() { if ( willPropagateSpyEvents() ) { reportSpyEvent( new ObservableValueChangeEvent( asInfo(), getObservableValue() ) ); } getContext().getTransaction().reportChangeConfirmed( this ); } ObservableValue( @Nullable final ArezContext context, @N...
@Test public void reportChangeConfirmed() { final ArezContext context = Arez.context(); final Observer observer = newReadWriteObserver( context ); setCurrentTransaction( observer ); observer.setState( Observer.Flags.STATE_POSSIBLY_STALE ); final ComputableValue<String> computableValue = context.computable( () -> "" ); ...
ArezUtil { @Nonnull @OmitSymbol( unless = "arez.enable_names" ) static String throwableToString( @Nonnull final Throwable throwable ) { final StringBuilder sb = new StringBuilder(); Throwable t = throwable; while ( null != t ) { addCausedByPrefix( sb ); sb.append( t.toString() ); for ( final StackTraceElement element :...
@Test public void throwableToString() { final String text = ArezUtil.throwableToString( new RuntimeException( "X" ) ); assertTrue( text.startsWith( "java.lang.RuntimeException: X\n" ) ); } @Test public void throwableToString_with_NestedThrowable() { final RuntimeException exception = new RuntimeException( "X", new IOEx...
ObservableValue extends Node { @SuppressWarnings( "ConstantConditions" ) @OmitSymbol( unless = "arez.enable_spies" ) @Nonnull ObservableValueInfo asInfo() { if ( Arez.shouldCheckInvariants() ) { invariant( Arez::areSpiesEnabled, () -> "Arez-0196: ObservableValue.asInfo() invoked but Arez.areSpiesEnabled() returned fals...
@Test public void asInfo() { final ObservableValue<String> observableValue = Arez.context().observable(); final ObservableValueInfo info = observableValue.asInfo(); assertEquals( info.getName(), observableValue.getName() ); }
Component implements Disposable { @Nonnull public Object getId() { return _id; } Component( @Nullable final ArezContext context, @Nonnull final String type, @Nonnull final Object id, @Nullable final String name, @Nullable final SafeProcedure preDispose, @...
@Test public void basicOperationIntegerId() { final Integer id = ValueUtil.randomInt(); final Component component = new Component( Arez.context(), ValueUtil.randomString(), id, ValueUtil.randomString(), null, null ); assertEquals( component.getId(), id ); }
Component implements Disposable { public void complete() { if ( !_complete ) { _complete = true; if ( Arez.areSpiesEnabled() && getContext().getSpy().willPropagateSpyEvents() ) { final ComponentInfo component = getContext().getSpy().asComponentInfo( this ); getContext().getSpy().reportSpyEvent( new ComponentCreateCompl...
@Test public void complete() { final ArezContext context = Arez.context(); final String name = ValueUtil.randomString(); final Component component = context.component( ValueUtil.randomString(), ValueUtil.randomString(), name ); final ObservableValue<?> observableValue1 = context.observable(); final ComputableValue<?> c...
Component implements Disposable { @Override public void dispose() { if ( !_disposed ) { _disposed = true; if ( Arez.areSpiesEnabled() && getContext().getSpy().willPropagateSpyEvents() ) { final ComponentInfo info = getContext().getSpy().asComponentInfo( this ); getContext().getSpy().reportSpyEvent( new ComponentDispose...
@Test public void dispose() { final ArezContext context = Arez.context(); final String name = ValueUtil.randomString(); final Component component = context.component( ValueUtil.randomString(), ValueUtil.randomString(), name ); final ObservableValue<?> observableValue1 = context.observable( component, ValueUtil.randomSt...
Component implements Disposable { @SuppressWarnings( "ConstantConditions" ) @OmitSymbol( unless = "arez.enable_spies" ) @Nonnull ComponentInfo asInfo() { if ( Arez.shouldCheckInvariants() ) { invariant( Arez::areSpiesEnabled, () -> "Arez-0194: Component.asInfo() invoked but Arez.areSpiesEnabled() returned false." ); } ...
@Test public void asInfo() { final ArezContext context = Arez.context(); final Component component = context.component( ValueUtil.randomString(), ValueUtil.randomString(), ValueUtil.randomString() ); final ComponentInfo info = component.asInfo(); assertEquals( info.getId(), component.getId() ); assertEquals( info.getNa...
Component implements Disposable { Component( @Nullable final ArezContext context, @Nonnull final String type, @Nonnull final Object id, @Nullable final String name, @Nullable final SafeProcedure preDispose, @Nullable final SafeProcedure postDispose ) { if ( Arez.shouldCheckApiInvariants() ) { apiInvariant( () -> Arez.a...
@Test public void asInfo_spyDisabled() { ArezTestUtil.disableSpies(); final ArezContext context = Arez.context(); final Component component = context.component( ValueUtil.randomString(), ValueUtil.randomString(), ValueUtil.randomString() ); assertInvariantFailure( component::asInfo, "Arez-0194: Component.asInfo() invok...
Observer extends Node { void invariantDependenciesBackLink( @Nonnull final String context ) { if ( Arez.shouldCheckInvariants() ) { getDependencies().forEach( observable -> invariant( () -> observable.getObservers().contains( this ), () -> "Arez-0090: " + context + ": Observer named '" + getName() + "' has ObservableVa...
@Test public void invariantDependenciesBackLink() { final Observer observer = Arez.context().observer( new CountAndObserveProcedure() ); setCurrentTransaction( observer ); final ObservableValue<?> observableValue = Arez.context().observable(); observer.getDependencies().add( observableValue ); assertInvariantFailure( (...
Observer extends Node { void invariantDependenciesNotDisposed() { if ( Arez.shouldCheckInvariants() ) { getDependencies().forEach( observable -> invariant( observable::isNotDisposed, () -> "Arez-0091: Observer named '" + getName() + "' has " + "ObservableValue dependency named '" + observable.getName() + "' which is di...
@Test public void invariantDependenciesNotDisposed() { final Observer observer = Arez.context().observer( new CountAndObserveProcedure() ); setCurrentTransaction( observer ); final ObservableValue<?> observableValue = Arez.context().observable(); observer.getDependencies().add( observableValue ); observableValue.addObs...