# Verify that we use create-time based ordering for replicated write admission
# when done so across different ranges.

init
----
[regular] 0B tokens available
[elastic] 0B tokens available

# Admit two requests, one created at t=5us with a lower log position on r1.
admit tenant=t1 pri=normal-pri create-time=5us size=1B range=r1 origin=n1 log-position=4/20
----
[regular] try-get=1B available=0B => insufficient tokens

# And one created at t=1us with a higher log position on r2.
admit tenant=t1 pri=normal-pri create-time=1us size=1B range=r2 origin=n1 log-position=4/21
----

# Observe both waiting requests and physical admission stats. Note that the
# request with the lower create time sorts first despite having the higher log
# position. Admission work queues order work based entirely on create-times,
# and the assignment of monotonic create-times (WRT log positions) happens only
# within a range by the StoreWorkQueue.
print
----
physical-stats: work-count=2 written-bytes=2B ingested-bytes=0B
[regular work queue]: len(tenant-heap)=1 top-tenant=t1
 tenant=t1 weight=1 fifo-threshold=low-pri used=0B
  [0: pri=normal-pri create-time=1µs size=1B range=r2 origin=n1 log-position=4/21]
  [1: pri=normal-pri create-time=5µs size=1B range=r1 origin=n1 log-position=4/20]
[elastic work queue]: len(tenant-heap)=0

# Produce 1B worth of regular tokens.
granter class=regular adjust-tokens=+1B
----
[regular] 1B tokens available
[elastic] 0B tokens available

# Grant admission to requests. Since we have 1B worth of tokens, and 2 waiting
# requests wanting 1B each, we're only able to admit one. Verify that it's the
# request with the lower create-time.
grant class=regular
----
admitted [tenant=t1 pri=normal-pri create-time=1µs size=1B range=r2 origin=n1 log-position=4/21]

print
----
physical-stats: work-count=2 written-bytes=2B ingested-bytes=0B
[regular work queue]: len(tenant-heap)=1 top-tenant=t1
 tenant=t1 weight=1 fifo-threshold=low-pri used=1B
  [0: pri=normal-pri create-time=5µs size=1B range=r1 origin=n1 log-position=4/20]
[elastic work queue]: len(tenant-heap)=0

# vim:ft=sh
