Tm1EngineContainer
using Skipcheck.Tm1.Testcontainers; A TM1 v12 engine (Planning Analytics 3.x) in Docker, for tests: the tm1-engine
image with TM1 from a Tm1EngineSource, and the MongoDB it keeps its metadata
in, on a network of their own. For TM1 11, use Tm1ServerContainer.
One engine holds instances, each holding databases. Most tests use the
one instance, tm1, and a database of their own: RequiresTm1EngineFactAttribute gives
each test class one. A container you make yourself has the databases you name with
WithDatabase, or one called tm1:
await using var engine = new Tm1EngineContainer(source).WithDatabase("planning").WithUser("analyst", "Analysts");
await engine.StartAsync();
var planning = engine.Database("planning");
// http://localhost:54321/tm1/api/v1/Databases('planning')/
var url = planning.RestUrl;
var analyst = planning.Login("analyst");
// ...
TM1 v12 has no passwords of its own. A test logs in through the instance's application
(Tm1Login), which this container creates and keeps the credentials of.
Starting takes about 40 seconds, and a database about 10 more to create
(CreateDatabaseAsync). The image exists for x86-64 only, as TM1 does; on Apple
Silicon it runs under Rosetta.
Members
DefaultImage static | The tm1-engine image, without its tag (the library's version, or edge). |
EngineImage static | The setting that replaces DefaultImage (not used with Tm1EngineSource.PrivateImage), e.g. |
DatastoreImage static | The MongoDB image the engine's datastore runs. |
Port static | The port of TM1's gateway inside the container. |
DefaultInstance static | The instance databases are in unless one is named. |
DefaultDatabase static | The database a container has when none is named. |
DatastoreAlias static | The datastore's name on the engine's network. |
CacheVolume static | The volume package installs are cached in, shared by every engine container on this Docker host (and with the Java, Python and TypeScript tests). |
OAuth2Realm static | The Keycloak realm an engine with WithOAuth2 takes tokens from. |
OAuth2Client static | The client of that realm a test asks for tokens as, and the audience its tokens carry. |
PassThroughAlias static | The name a TM1 server has on the engine's network when logins are passed to it (WithPassThrough). |
Tm1EngineContainer constructor | TM1 from source, in the default image for it. |
Tm1EngineContainer constructor | TM1 from source, in an image of your own, such as a locally built one. |
SharedAsync static | The engine most tests share. |
WithDatabase | Adds a database, in the instance tm1. |
WithDatabase | Adds a database in a named instance, which is created with an application of its own. |
WithUser | Adds a user to every database, in exactly these groups (created if missing). |
WithOAuth2 | Takes OAuth 2.0 logins. |
WithPassThrough | Passes logins on to a TM1 11 server ("pass-through"). |
PassThrough property | The TM1 server logins are passed to, or null without WithPassThrough. |
WithLogin | Gives a user a password to log in with through OAuth 2.0 (WithOAuth2). |
Keycloak property | The Keycloak the engine takes OAuth 2.0 tokens from, or null without WithOAuth2. |
Source property | Where TM1 comes from. |
Datastore property | The MongoDB the engine keeps its metadata in, started and stopped with it. |
Url property | The gateway as seen from the host, ending in /, e.g. |
ManagementUrl property | The management API, which lists and creates instances, applications and databases, ending in /, e.g. |
RootClientId property | The client ID of the engine's root credentials, for the management API. |
RootClientSecret property | The client secret of the engine's root credentials. |
Tm1Version property | The version of TM1 the engine runs. |
DatabasesAsync | The databases the engine has now, in every instance, read from the engine again. |
Database | A database of the instance tm1. |
Database | A database of a named instance. |
CreateDatabaseAsync | Creates a database in the instance tm1 of the running engine, with the users of WithUser. |
CreateDatabaseAsync | Creates a database in a named instance of the running engine, which must exist. |
DropDatabaseAsync | Deletes a database of the running engine, with everything in it. |
DockerImageName property | The image it runs. |
EnvMap property | Its environment variables, so far. |
CommandParts property | The command it runs, if not the image's. |
ExposedPorts property | The ports it exposes on the Docker host. |
Network property | The network it joins, or null for Docker's default bridge. |
NetworkAliases property | Its names on Network. |
Dependencies property | What starts before it. |
Container property | The started container. |
IsRunning property | |
Host property | The host its ports are mapped on. |
ContainerId property | The Docker container's ID. |
GetMappedPort | The host port port is mapped to. |
WithEnv | Sets an environment variable. |
WithEnv | Sets environment variables. |
WithCommand | Runs commandParts in place of the image's command. |
WithExposedPorts | Exposes ports on the Docker host, each on a free port. |
WithNetwork | Joins network (created when the first container on it starts). |
WithNetworkAliases | Adds names it's reached by on Network. |
DependsOn | Starts startables before it. |
WithExtraHost | Adds an /etc/hosts entry. |
WithReuse | Keeps the container for later runs, when reuse is switched on as Testcontainers for Java has it (testcontainers.reuse.enable=true in ~/.testcontainers.properties, or TESTCONTAINERS_REUSE_ENABLE=true); otherwise it's removed after the run. |
WithCopyFileToContainer | Copies a host file or folder into the container before it starts. |
WithStartupTimeout | How long to wait for it to be ready. |
StartAsync | |
StopAsync | |
DisposeAsync | Stops it. |
GetLogsAsync | Its log, so far. |
DefaultImage
staticconst string DefaultImageThe tm1-engine image, without its tag (the library's version, or edge).
EngineImage
staticconst string EngineImageThe setting that replaces DefaultImage (not used with
Tm1EngineSource.PrivateImage), e.g. tm1-engine:local for a local build.
DatastoreImage
staticconst string DatastoreImageThe MongoDB image the engine's datastore runs.
Port
staticconst int PortThe port of TM1's gateway inside the container: the REST API, logins and management.
DefaultInstance
staticconst string DefaultInstanceThe instance databases are in unless one is named.
DefaultDatabase
staticconst string DefaultDatabaseThe database a container has when none is named.
DatastoreAlias
staticconst string DatastoreAliasThe datastore's name on the engine's network.
CacheVolume
staticconst string CacheVolumeThe volume package installs are cached in, shared by every engine container on this Docker host (and with the Java, Python and TypeScript tests). Only the first container to see a package installs it. Remove the volume to clear it.
OAuth2Realm
staticconst string OAuth2RealmThe Keycloak realm an engine with WithOAuth2 takes tokens from.
OAuth2Client
staticconst string OAuth2ClientThe client of that realm a test asks for tokens as, and the audience its tokens carry.
PassThroughAlias
staticconst string PassThroughAliasThe name a TM1 server has on the engine's network when logins are passed to it
(WithPassThrough).
Tm1EngineContainer
constructorTm1EngineContainer(Tm1EngineSource source)TM1 from source, in the default image for it: a private image as it
is; otherwise TM1_ENGINE_IMAGE if set; otherwise DefaultImage tagged with
this library's version (edge for a development build).
Tm1EngineContainer
constructorTm1EngineContainer(string image, Tm1EngineSource source)TM1 from source, in an image of your own, such as a locally built one.
WithDatabase
Tm1EngineContainer WithDatabase(string name)Adds a database, in the instance tm1. Without any, the container has one called
tm1.
Parameters
name- The database's name: at least three letters, digits,
_or-.Salesandsalesare two databases.
Throws
ArgumentException- The image can't take the name.
WithDatabase
Tm1EngineContainer WithDatabase(string instance, string name)Adds a database in a named instance, which is created with an application of its own. An instance's users, sessions and applications are separate from another's.
Throws
ArgumentException- The image can't take a name.
WithUser
Tm1EngineContainer WithUser(string name, params string[] groups)Adds a user to every database, in exactly these groups (created if missing). A new
database has one user already: admin, in the ADMIN group.
Throws
ArgumentException- The image can't take a name, or the user is already added.
WithOAuth2
Tm1EngineContainer WithOAuth2(KeycloakContainer keycloak)Takes OAuth 2.0 logins: tokens from a Keycloak, which gets a realm (tm1) with the users given a
password by WithLogin. A test then logs in with Tm1Database.OAuth2Login. Logins through
the engine's application (Tm1Database.Login) keep working beside it.
The Keycloak joins the engine's network, unless it has one already, which the engine then joins. It's yours to stop: the engine only starts it first. An engine has one Keycloak, and a Keycloak one engine: the same Keycloak again changes nothing.
// Starting the engine starts Keycloak first; the Keycloak is yours to stop
await using var keycloak = new KeycloakContainer();
await using var engine = new Tm1EngineContainer(source).WithUser("analyst", "Analysts").WithLogin("analyst", "analystpw").WithOAuth2(keycloak);
await engine.StartAsync();
var db = engine.Database("tm1");
// A token from Keycloak, with the analyst's password, sent to TM1 as Bearer
using var request = new HttpRequestMessage(HttpMethod.Get, db.RestUrl + "Cubes?$select=Name");
await db.OAuth2Login("analyst").AuthorizeWithTokenAsync(request);Throws
InvalidOperationException- The engine has another Keycloak, or passes logins on
(
WithPassThrough); or this Keycloak is already running, or is another engine's.
WithPassThrough
Tm1EngineContainer WithPassThrough(Tm1ServerContainer server)Passes logins on to a TM1 11 server ("pass-through"): TM1 v12 asks it who a login is, so that server's
users log in here with what they have there. A test logs in with Tm1Database.PassThroughLogin.
Logins through the engine's application (Tm1Database.Login) keep working beside it.
A user has to be in the database too: add each with WithUser. admin always is.
A server in Cognos (CAM) security
(Tm1ServerContainer.WithCamSecurity) answers a login with the user's
CAMID. The engine's users are then Cognos's test users, each made under its CAMID, and the server's
administrators are administrators here too. TM1 v12 learns no groups from Cognos: a user has the groups
WithUser gives.
Not together with WithOAuth2: with both, TM1 takes tokens and refuses the rest.
The server joins the engine's network, unless it has one already, which the engine and its datastore then
join. Starting the engine starts the server first. Give it one that isn't started: it gets the name the engine
reaches it by, PassThroughAlias, so one network holds one such server. The server is yours to
stop.
// Starting the engine starts the TM1 11 server first; the server is yours to stop
await using var server = new Tm1ServerContainer(tm1).WithSeed(Tm1Seed.Sdata);
await using var engine = new Tm1EngineContainer(source).WithPassThrough(server);
await engine.StartAsync();
var db = engine.Database("tm1");
// The sample database's admin / apple, which TM1 v12 asks the server about
using var request = new HttpRequestMessage(HttpMethod.Get, db.RestUrl + "Cubes?$select=Name");
await db.PassThroughLogin().AuthorizeAsync(request);Parameters
server- The TM1 server that checks logins.
Returns
- This container.
Throws
InvalidOperationException- The engine passes logins to another server already, or takes OAuth 2.0 tokens; or the server is already running, or checks logins for another engine.
PassThrough
propertyTm1ServerContainer? PassThroughThe TM1 server logins are passed to, or null without WithPassThrough.
WithLogin
Tm1EngineContainer WithLogin(string user, string password)Gives a user a password to log in with through OAuth 2.0 (WithOAuth2). TM1 v12 keeps no
passwords itself: it's the Keycloak's. The user is one added with WithUser, or admin.
Throws
ArgumentException- The name isn't a user's, or the password is empty.
Keycloak
propertyKeycloakContainer? KeycloakThe Keycloak the engine takes OAuth 2.0 tokens from, or null without WithOAuth2.
Source
propertyTm1EngineSource SourceWhere TM1 comes from.
Datastore
propertyDatastoreContainer DatastoreThe MongoDB the engine keeps its metadata in, started and stopped with it.
Url
propertystring UrlThe gateway as seen from the host, ending in /, e.g. http://localhost:54321/.
ManagementUrl
propertystring ManagementUrlThe management API, which lists and creates instances, applications and databases,
ending in /, e.g. http://localhost:54321/manage/v1/. It takes the root
credentials as Basic authentication (RootClientId, RootClientSecret).
RootClientId
propertystring RootClientIdThe client ID of the engine's root credentials, for the management API.
Throws
InvalidOperationException- It isn't started.
RootClientSecret
propertystring RootClientSecretThe client secret of the engine's root credentials.
Throws
InvalidOperationException- It isn't started.
Tm1Version
propertyTm1Version Tm1VersionThe version of TM1 the engine runs. Only available once started.
Throws
InvalidOperationException- It isn't started.
DatabasesAsync
Task<IReadOnlyList<Tm1Database>> DatabasesAsync(CancellationToken cancellationToken = default)The databases the engine has now, in every instance, read from the engine again.
Throws
InvalidOperationException- It isn't started.
Database
Tm1Database Database(string name)A database of the instance tm1.
Throws
ArgumentException- There's no such database.
Database
Tm1Database Database(string instance, string name)A database of a named instance: of those the engine had when it started, or was last
asked (DatabasesAsync, CreateDatabaseAsync,
DropDatabaseAsync); before it starts, of those added with WithDatabase.
Throws
ArgumentException- There's no such database.
CreateDatabaseAsync
Task<Tm1Database> CreateDatabaseAsync(string name, CancellationToken cancellationToken = default)Creates a database in the instance tm1 of the running engine, with the users of
WithUser. Takes about 10 seconds.
Throws
InvalidOperationException- It isn't started, or TM1 refuses.
CreateDatabaseAsync
Task<Tm1Database> CreateDatabaseAsync(string instance, string name, CancellationToken cancellationToken = default)Creates a database in a named instance of the running engine, which must exist. If that fails, what was made of the database is dropped again.
Throws
InvalidOperationException- It isn't started, or TM1 refuses.
DropDatabaseAsync
Task DropDatabaseAsync(Tm1Database database, CancellationToken cancellationToken = default)Deletes a database of the running engine, with everything in it. Takes about 7 seconds.
Throws
InvalidOperationException- It isn't started, or TM1 refuses.
DockerImageName
propertystring DockerImageNameThe image it runs.
EnvMap
propertyIReadOnlyDictionary<string, string> EnvMapIts environment variables, so far.
CommandParts
propertyIReadOnlyList<string> CommandPartsThe command it runs, if not the image's.
ExposedPorts
propertyIReadOnlyList<int> ExposedPortsThe ports it exposes on the Docker host.
Network
propertyNetwork? NetworkThe network it joins, or null for Docker's default bridge.
NetworkAliases
propertyIReadOnlyList<string> NetworkAliasesIts names on Network.
Dependencies
propertyIReadOnlyCollection<IStartable> DependenciesWhat starts before it.
Container
propertyIContainer ContainerThe started container.
Throws
InvalidOperationException- It isn't started.
IsRunning
propertybool IsRunningHost
propertystring HostThe host its ports are mapped on.
ContainerId
propertystring ContainerIdThe Docker container's ID.
GetMappedPort
int GetMappedPort(int port)The host port port is mapped to.
WithEnv
TSelf WithEnv(string name, string value)Sets an environment variable.
WithEnv
TSelf WithEnv(IReadOnlyDictionary<string, string> variables)Sets environment variables.
WithCommand
TSelf WithCommand(params string[] commandParts)Runs commandParts in place of the image's command.
WithExposedPorts
TSelf WithExposedPorts(params int[] exposedPorts)Exposes ports on the Docker host, each on a free port.
WithNetwork
TSelf WithNetwork(Network? network)Joins network (created when the first container on it starts).
WithNetworkAliases
TSelf WithNetworkAliases(params string[] networkAliases)Adds names it's reached by on Network.
DependsOn
TSelf DependsOn(params IStartable[] startables)Starts startables before it.
WithExtraHost
TSelf WithExtraHost(string host, string ipAddress)Adds an /etc/hosts entry.
WithReuse
TSelf WithReuse(bool reusable)Keeps the container for later runs, when reuse is switched on as Testcontainers for
Java has it (testcontainers.reuse.enable=true in ~/.testcontainers.properties,
or TESTCONTAINERS_REUSE_ENABLE=true); otherwise it's removed after the run.
WithCopyFileToContainer
TSelf WithCopyFileToContainer(string hostPath, string containerPath)Copies a host file or folder into the container before it starts.
WithStartupTimeout
TSelf WithStartupTimeout(TimeSpan timeout)How long to wait for it to be ready.
StartAsync
Task StartAsync(CancellationToken cancellationToken = default)StopAsync
Task StopAsync(CancellationToken cancellationToken = default)DisposeAsync
ValueTask DisposeAsync()Stops it.
GetLogsAsync
Task<string> GetLogsAsync(CancellationToken cancellationToken = default)Its log, so far.