Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ZFlowSchedule #325

Merged
merged 3 commits into from
Nov 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -806,20 806,23 @@ final case class PersistentExecutor(
else
onError(error)

case NewVar(name, initial) =>
case NewVar(name, initial, appendTempCounter) =>
for {
initialValue <- RemoteContext.evalDynamic(initial)
finalName = if (appendTempCounter) s"${name}_${state.tempVarCounter}}" else name
remoteVariableName <-
RemoteVariableName
.make(name)
.make(finalName)
.toZIO
.mapError(msg =>
ExecutorError.InvalidOperationArguments(s"Failed to create remote variable with name $name: $msg")
ExecutorError
.InvalidOperationArguments(s"Failed to create remote variable with name $finalName: $msg")
)
vref = RemoteVariableReference[Any](remoteVariableName)
_ <- RemoteContext.setVariable(remoteVariableName, initialValue)
_ <- ZIO.logDebug(s"Created new variable $name")
result <- onSuccess(Remote(vref), StateChange.none)
vref = RemoteVariableReference[Any](remoteVariableName)
_ <- RemoteContext.setVariable(remoteVariableName, initialValue)
_ <- ZIO.logDebug(s"Created new variable $finalName")
result <-
onSuccess(Remote(vref), if (appendTempCounter) StateChange.increaseTempVarCounter else StateChange.none)
} yield result

case i @ Iterate(initial, step0, predicate) =>
Expand Down
7 changes: 4 additions & 3 deletions zio-flow-runtime/src/test/scala/zio/flow/MockExecutors.scala
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 20,17 @@ import zio.flow.mock.{MockedOperation, MockedOperationExecutor}
import zio.flow.runtime.internal.PersistentExecutor
import zio.flow.runtime.{DurableLog, KeyValueStore, ZFlowExecutor}
import zio.flow.serialization.{Deserializer, Serializer}
import zio.{Scope, ZIO, ZLayer}
import zio.{Duration, Scope, ZIO, ZLayer, durationInt}

object MockExecutors {
def persistent(
mockedOperations: MockedOperation = MockedOperation.Empty
mockedOperations: MockedOperation = MockedOperation.Empty,
gcPeriod: Duration = 5.minutes
): ZIO[Scope with DurableLog with KeyValueStore with Configuration, Nothing, ZFlowExecutor] =
MockedOperationExecutor.make(mockedOperations).flatMap { operationExecutor =>
((DurableLog.any KeyValueStore.any Configuration.any ZLayer.succeed(operationExecutor) ZLayer
.succeed(Serializer.json) ZLayer.succeed(Deserializer.json)) >>>
PersistentExecutor
.make()).build.map(_.get[ZFlowExecutor])
.make(gcPeriod)).build.map(_.get[ZFlowExecutor])
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,24 19,29 @@ package zio.flow
import zio.flow.mock.MockedOperation
import zio.flow.runtime.{DurableLog, ExecutorError, KeyValueStore, ZFlowExecutor}
import zio.schema.{DynamicValue, Schema}
import zio.{Duration, Fiber, Scope, ZIO}
import zio.{Duration, Fiber, Scope, ZIO, durationInt}

object ZFlowAssertionSyntax {

implicit final class InMemoryZFlowAssertion[E, A](private val zflow: ZFlow[Any, E, A]) {
def evaluateTestPersistent(id: String, mock: MockedOperation = MockedOperation.Empty)(implicit
def evaluateTestPersistent(
id: String,
mock: MockedOperation = MockedOperation.Empty,
gcPeriod: Duration = 5.minutes
)(implicit
schemaA: Schema[A],
schemaE: Schema[E]
): ZIO[DurableLog with KeyValueStore with Configuration, E, A] =
ZIO.scoped {
submitTestPersistent(id, mock).flatMap(_._2.join)
submitTestPersistent(id, mock, gcPeriod).flatMap(_._2.join)
}

def submitTestPersistent(id: String, mock: MockedOperation = MockedOperation.Empty)(implicit
def submitTestPersistent(id: String, mock: MockedOperation = MockedOperation.Empty, gcPeriod: Duration = 5.minutes)(
implicit
schemaA: Schema[A],
schemaE: Schema[E]
): ZIO[Scope with DurableLog with KeyValueStore with Configuration, E, (ZFlowExecutor, Fiber[E, A])] =
MockExecutors.persistent(mock).flatMap { executor =>
MockExecutors.persistent(mock, gcPeriod).flatMap { executor =>
executor.restartAll().orDieWith(_.toException) *>
executor.run(FlowId.unsafeMake(id), zflow).forkScoped.map(fiber => (executor, fiber))
}
Expand Down
16 changes: 16 additions & 0 deletions zio-flow-runtime/src/test/scala/zio/flow/ZIOFlowBaseSpec.scala
Original file line number Diff line number Diff line change
@@ -1,3 1,19 @@
/*
* Copyright 2021-2022 John A. De Goes and the ZIO Contributors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package zio.flow

import zio.ZLayer
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 1,184 @@
/*
* Copyright 2021-2022 John A. De Goes and the ZIO Contributors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package zio.flow.remote

import zio.{Scope, ZLayer}
import zio.flow._
import zio.flow.runtime.internal.InMemoryRemoteContext
import zio.flow.utils.RemoteAssertionSyntax.RemoteAssertionOps
import zio.test._

import java.time.ZoneOffset

object RemoteOffsetDateTimeSpec extends RemoteSpecBase {
override def spec: Spec[TestEnvironment with Scope, Any] =
suite("RemoteOffsetDateTimeSyntax")(
test("ofInstant")(
check(Gen.instant, Gen.zoneOffset) { (instant, offset) =>
OffsetDateTime.ofInstant(Remote(instant), Remote(offset)) <-> java.time.OffsetDateTime
.ofInstant(instant, offset)
}
),
test("of")(
check(Gen.offsetDateTime)(dt =>
OffsetDateTime.of(
dt.getYear,
dt.getMonthValue,
dt.getDayOfMonth,
dt.getHour,
dt.getMinute,
dt.getSecond,
dt.getNano,
dt.getOffset
) <-> dt
)
),
test("toInstant")(
check(Gen.instant) { instant =>
OffsetDateTime.ofInstant(instant, ZoneOffset.UTC).toInstant <-> instant
}
),
test("getYear")(
check(Gen.offsetDateTime)(dt =>
OffsetDateTime
.of(
dt.getYear,
dt.getMonthValue,
dt.getDayOfMonth,
dt.getHour,
dt.getMinute,
dt.getSecond,
dt.getNano,
dt.getOffset
)
.getYear <-> dt.getYear
)
),
test("getMonthValue")(
check(Gen.offsetDateTime)(dt =>
OffsetDateTime
.of(
dt.getYear,
dt.getMonthValue,
dt.getDayOfMonth,
dt.getHour,
dt.getMinute,
dt.getSecond,
dt.getNano,
dt.getOffset
)
.getMonthValue <-> dt.getMonthValue
)
),
test("getDayOfMonth")(
check(Gen.offsetDateTime)(dt =>
OffsetDateTime
.of(
dt.getYear,
dt.getMonthValue,
dt.getDayOfMonth,
dt.getHour,
dt.getMinute,
dt.getSecond,
dt.getNano,
dt.getOffset
)
.getDayOfMonth <-> dt.getDayOfMonth
)
),
test("getHour")(
check(Gen.offsetDateTime)(dt =>
OffsetDateTime
.of(
dt.getYear,
dt.getMonthValue,
dt.getDayOfMonth,
dt.getHour,
dt.getMinute,
dt.getSecond,
dt.getNano,
dt.getOffset
)
.getHour <-> dt.getHour
)
),
test("getMinute")(
check(Gen.offsetDateTime)(dt =>
OffsetDateTime
.of(
dt.getYear,
dt.getMonthValue,
dt.getDayOfMonth,
dt.getHour,
dt.getMinute,
dt.getSecond,
dt.getNano,
dt.getOffset
)
.getMinute <-> dt.getMinute
)
),
test("getSecond")(
check(Gen.offsetDateTime)(dt =>
OffsetDateTime
.of(
dt.getYear,
dt.getMonthValue,
dt.getDayOfMonth,
dt.getHour,
dt.getMinute,
dt.getSecond,
dt.getNano,
dt.getOffset
)
.getSecond <-> dt.getSecond
)
),
test("getNano")(
check(Gen.offsetDateTime)(dt =>
OffsetDateTime
.of(
dt.getYear,
dt.getMonthValue,
dt.getDayOfMonth,
dt.getHour,
dt.getMinute,
dt.getSecond,
dt.getNano,
dt.getOffset
)
.getNano <-> dt.getNano
)
),
test("getOffset")(
check(Gen.offsetDateTime)(dt =>
OffsetDateTime
.of(
dt.getYear,
dt.getMonthValue,
dt.getDayOfMonth,
dt.getHour,
dt.getMinute,
dt.getSecond,
dt.getNano,
dt.getOffset
)
.getOffset <-> dt.getOffset
)
)
).provide(ZLayer(InMemoryRemoteContext.make), LocalContext.inMemory)
}
Original file line number Diff line number Diff line change
@@ -1,3 1,19 @@
/*
* Copyright 2021-2022 John A. De Goes and the ZIO Contributors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package zio.flow.runtime.internal

import zio.flow.runtime.operation.http.{Repetition, RetryLimit, RetryPolicy}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 1,19 @@
/*
* Copyright 2021-2022 John A. De Goes and the ZIO Contributors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package zio.flow.runtime.internal

import zio.flow.runtime.IndexedStore.Index
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 1,19 @@
/*
* Copyright 2021-2022 John A. De Goes and the ZIO Contributors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package zio.flow.runtime.internal

import zio.flow._
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 1,19 @@
/*
* Copyright 2021-2022 John A. De Goes and the ZIO Contributors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package zio.flow.runtime.internal

import zio.flow.{FlowId, RemoteVariableName, TransactionId}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 1,19 @@
/*
* Copyright 2021-2022 John A. De Goes and the ZIO Contributors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package zio.flow.runtime.internal

import zhttp.http.Status
Expand Down
Loading